the while loop in isTwo() never happens because next is bound to be bigger than size right off the bat. The value of line here will be the ascii value of the first letter, probably in the range 32-127:
Code:
int next = (*line) + 1;
See what you get if you insert this line next:
Code:
printf ("isTwo(): %d\n", next);
Now a question from me: why do you do this:
Code:
char array[MAXLEN];
char *p;
p = &array[0];
and then pass isTwo() p? It would have been sufficient to just use char array[MAXLEN] and then pass array.
Anyway, here is a somewhat corrected version of your program that I think does want you want:
Code:
/****************************************************************/
/* doublekiller */
/* searches through a given word and removes */
/* double letters */
/****************************************************************/
#include <stdio.h>
#include <string.h>
#define MAXLEN 400
void isTwo(char *line, int size);
int main(void)
{
char array[MAXLEN];
fgets(array, MAXLEN, stdin);
isTwo(array, strlen(array)); //this addresses the INITIAL element to the function. so '&array' == '&array[0]'
printf("%s\n", array);
return 0;
}
void isTwo(char *line, int size) //tests the given string for doubles and removes them
{
int next = 0;
while(next < size)//this could have been a for loop. i decided to write the entire thing out for my clarity.
{
if(line[next] == line[next+1]) line[next]='_';
next++;
}
}
Output:
A version using pointers in isTwo() might be:
Code:
void isTwo(char *line, int size) //tests the given string for doubles and removes them
{
int i=0;
char *next=line+1;
while(i < size)//this could have been a for loop. i decided to write the entire thing out for my clarity.
{
if(*line == *next) *line='_';
line++; next++;
i++;
}
}