[Solved] my output of link list is not correct? [closed]


Remember pressing Enter after entering data for the previous scanf? This newline character is consumed by the scanf with a %c.

You have to change

scanf("%c",&ch);
fflush(stdin);

to

scanf(" %c", &ch);

so that the scanf will skip the newline character left over by the previous scanf. The space before %c is a whitespace character and whitespace characters in the format string of scanf tells scanf to scan and discard any number of whitespace characters, if any, until the first non-whitespace character.

And fflush(stdin); is undefined as per the C standard although some implementations define its behavior. Basically, you should avoid it to increase portability.

5

solved my output of link list is not correct? [closed]