本来以为之前的那个挨个读的程序没有问题了,结果代码刚插入到工程了就出现问题了,while循环直接略过,循环体根本没有执行,喵了个咪,这是个什么情况!
排查了一下,发现是把上面一个输入流的\n读进来了,所以循环条件不成立,知道原因就好改了,代码如下:
#include <stdio.h>
#define LEN 30
void get_string(char * string, int len)
{
char ch;
int i=0;
while((ch=getchar())=='\n');
while(ch!='\n' && i<len-2 && i>=0 )
{
if(ch=='\b')
string[--i]='\0';
else
string[i++]=ch;
ch=getchar();