typedef struct node_s{
int data;
struct node_s *next;
}node_t;
void insert(node_t *pointer, int data){
while(pointer->next != NULL)
In addition to removing \n
from your scanf
statements, be aware that scanf
will read the data from the command line, filling the variable specified, but it will leave the \n
in the input buffer causing problems the next time scanf
is called. Since there is no standard command to flush input buffers, you are responsible for insuring that you do not have extraneous unused characters in the input buffer the next time scanf
is called. One simple way to handle manually flushing the input buffer after each scanf
if to simply use getchar()
to read any remaining characters in the input buffer until \n
is encountered. For example:
int c;
...
scanf ("format", &var);
do {
c = getchar();
while ( c != '\n' );
This will insure subsequent calls to scanf
retrieves the wanted data instead of passing the characters that remain in the input buffer.