Hi!
Code:
#include <stdio.h>
int stringlen(char* field, int length) {
int i = 0;
while(field[i] != '\0') {
i++;
}
return i;
}
int main() {
char text[100] = "Hello";
/* #define LAENGE 100
char array[LAENGE];
fgets(array, LAENGE, stdin);
*/
int laenge;
laenge = stringlen(text, 100);
printf("%d\n", laenge);
return 0;
}
If I would "uncomment" my commented out code and out-comment the used code in the main(), basically if I would use fgets for a string_userinput, then regards to my function the length (would not be "i", but "i - 1". Why is this?
Has it something with "stdin" to do?