Manipulating data in an array...
I wanted to write a program to scan an array and remove the double characters that it finds. On top of that I wanted to challenge myself by using pointers and i think that might where my problem is. Or my logic. Both are entirely possible.
Here's what I've got so far:
Code:
/****************************************************************/
/* doublekiller */
/* searches through a given word and removes */
/* double letters */
/****************************************************************/
#include <stdio.h>
#include <string.h>
#define MAXLEN 400
char isTwo(char *line, int size);
int main(void)
{
char array[MAXLEN];
char *p;
p = &array[0];
fgets(array, MAXLEN, stdin);
isTwo(p, strlen(array)); //this addresses the INITIAL element to the function. so '&array' == '&array[0]'
printf("%s\n", array);
return 0;
}
char isTwo(char *line, int size) //tests the given string for doubles and removes them
{
int next = (*line) + 1;
while(next < size)//this could have been a for loop. i decided to write the entire thing out for my clarity.
{
if(*line == next)
{
next = '_';
*line = '_';
*line++;
}
else *line++;
}
}
If you guys would take a look and see what I might be doing wrong I'd really appreciate it.
Thanks.