-
fgets & storing
hi all , i just have a problem concerning fgets
if i use fgets in a linked list structure
fgets (element->name,MAX,stdin);
where "name" is an element of struct~
how can i store the input from stdin , without , storing the newline character into the linked list??
-
> how can i store the input from stdin , without , storing the newline character into the linked list??
You can't - fgets comes with a newline appended.
So you have to get rid of it after calling fgets
Here's an easy way
Code:
char *p = strchr( element->name, '\n' );
if ( p != NULL ) *p = '\0';