#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void main(){
FILE *fp;
char istr[80];
char sign;
if((fp=fopen("test.txt","wt+"))==NULL)
{
printf("File cannot be opened!");
exit(1);
}
do{
printf("input a string:\n");
gets(istr);
fprintf(fp,"%s",istr);
printf("Do you wanna input another string?\nY yes, N no");
sign=getchar();
if(sign=='N')break;
}while(sign=='Y');
fclose(fp);
}
如上,想要输入一个字符串以后,提示是否再次输入,但是我的测试结果是
input a string:
hello,world
Do you wanna input another string?
Y yes, N noY
input a string:
Do you wanna input another string?
Y yes, N no
第二次没等我输入就Y或N了,这是怎么回事?
要怎么修改?多谢