用VC使用gets,放在前面就能用,放在后面就不行,求教
#include "stdio.h "
char rulestr[100][100];
int rule_no;
void main()
{ int i;
scanf( "%d ",&i);
printf( "Please type in the rules:\n ");
gets (rulestr[rule_no]);
printf( "%s ",rulestr[0]);
}
这样gets就不管用,但是把gets句子放在第一位就能运行,这是怎么回事
[解决办法]
scanf( "%d ",&i);
printf( "Please type in the rules:\n ");
gets (rulestr[rule_no]);
问题出在前面的scanf
它最后留下了一个换行没有取走,
导致gets直接得到一个换行.
解决办法是,在scanf后加个gets,
比如
scanf( "%d ",&i);
char temp[128];
gets(temp);
printf( "Please type in the rules:\n ");
gets (rulestr[rule_no]);