Still teaching myself C. This time, I'm trying to read a text from the keyboard using a function:
int read_line(char my_string[]) {
int characters;
fgets(my_string, sizeof(my_string), stdin);
characters = strlen(my_string);
printf("characters =%d, my_string=%s. \n", characters , my_string);
}
int main(int argc, char *argv[]) {
char line[MAX];
read_line(line);
}
When I enter in keyboard this:
abcdefg
I get this on the console:
characters =3, my_string=abc.
Why is C behaving in that way? What's the proper way to read a character string through a method?