I am a beginner, just learning C; so, please be patient with me.
I am trying to write a very simple program that goes through a string, counts the characters in each word, and then replaces those words with the number of their characters. My problem is that I am stuck in an infinite loop and cannot figure out why! Here is the code:
#define NEWLINE '\n'
#define SPACE ' '
int main(int argc, char *argv[]) {
int character;
int count = 0;
printf("\nType in a sentence of any lenght, then hit ENTER!\n");
character = getchar();
while (character != NEWLINE) {
while ((character != SPACE) || (character != NEWLINE)) {
count++;
character = getchar();
}
printf("%d ", count);
count = 0;
if (character != NEWLINE) {
character = getchar();
}
}
printf("\n");
system("PAUSE");
return 0;
}
Thanks for everyone who helped me! I guess I go back and study logical operators a bit more.
this will loop infinitely because the inverse:
will ALWAYS be false.
I suspect you mean