就是怎么按回车就print一个句子啊,然后不用关掉就一直可以自己按照编好的对话下去
#include <stdio.h>
int main()
{
char ch;
do
{
printf("press enter to continue, press other keys to exit");
} while ((ch = getchar()) == '\n');
return 0;
}
将你的对话一句作为一个字符串存在数组中,用while(getchar())作为阻塞,也就是输入任意字符,从数组中读取一个字符串并输出,就实现了按一下出一句话
回车也是一次按键输入,一次敲击回车键会产生
/r/n这两个字符,所以你就用一个无限循环while(1){
if(输入的是回车键)
{
输出句子
}
}
大概就是这个模式
press enter to continue, press other keys to exit
press enter to continue, press other keys to exit
press enter to continue, press other keys to exit
press enter to continue, press other keys to exit
press enter to continue, press other keys to exit
press enter to continue, press other keys to exit
press enter to continue, press other keys to exit
press enter to continue, press other keys to exit
press enter to continue, press other keys to exit
press enter to continue, press other keys to exit
press enter to continue, press other keys to exit
press enter to continue, press other keys to exit
press enter to continue, press other keys to exit1
Press any key to continue
printf("你想打印的话");
这种方法仅限VC及Windows
#include
while(_getch() == '\n')
{
//TODO: ...
}
if(ch = '\n')
{
printf("你要输入的话");
}