我的 link 列表输出不正确?
my output of link list is not correct?
1[In my link list program I have a problem in output.when second time the compiler ask my choice then its not accept my choice directly output is appears where the problem I can't get it.]2
记得在输入上一个 scanf
的数据后按 Enter 吗?此换行符由 scanf
和 %c
.
使用
你必须改变
scanf("%c",&ch);
fflush(stdin);
至
scanf(" %c", &ch);
这样 scanf
将跳过前一个 scanf
留下的换行符。 %c
之前的space是一个白色space字符,scanf
的格式字符串中的白色space字符告诉scanf
扫描并丢弃任何白色space字符的数量,如果有的话,直到第一个非白色space字符。
并且 fflush(stdin);
根据 C 标准未定义,尽管一些实现定义了它的行为。基本上,您应该避免它以增加可移植性。
1[In my link list program I have a problem in output.when second time the compiler ask my choice then its not accept my choice directly output is appears where the problem I can't get it.]2
记得在输入上一个 scanf
的数据后按 Enter 吗?此换行符由 scanf
和 %c
.
你必须改变
scanf("%c",&ch);
fflush(stdin);
至
scanf(" %c", &ch);
这样 scanf
将跳过前一个 scanf
留下的换行符。 %c
之前的space是一个白色space字符,scanf
的格式字符串中的白色space字符告诉scanf
扫描并丢弃任何白色space字符的数量,如果有的话,直到第一个非白色space字符。
并且 fflush(stdin);
根据 C 标准未定义,尽管一些实现定义了它的行为。基本上,您应该避免它以增加可移植性。