- Joined
- Jan 24, 2022
- Messages
- 7
- Reaction score
- 0
hi,
just trying to input a word and returning the number of letters the word has.
For some reason, my i counter always gets to 1 higher than the actual number of letters.
Why is this happening? (i understand it is easier to use strlen but just want to know why this is happening).
#include <stdio.h>
int main(void) {
char input[1042] = {};
printf("Input word:");
fgets(input, 1042, stdin);
int i = 0;
while (input != '\0') {
i++;
}
printf("%d", i);
return 0;
}
just trying to input a word and returning the number of letters the word has.
For some reason, my i counter always gets to 1 higher than the actual number of letters.
Why is this happening? (i understand it is easier to use strlen but just want to know why this is happening).
#include <stdio.h>
int main(void) {
char input[1042] = {};
printf("Input word:");
fgets(input, 1042, stdin);
int i = 0;
while (input != '\0') {
i++;
}
printf("%d", i);
return 0;
}