eclipse中的关于scanf和printf的输入顺序的解决办法
2013-04-02 13:59
447 查看
eclipse中的关于scanf和printf的输入顺序的解决办法
The eclipse console has weird behaviour when used for input with C programs.I teach C to first year undergraduates and I want them to learn their way through eclipse. But the small silly programs that ask you to input characters have weird behaviour, if you use the
eclipse console. It seems like it groups all input and output commands and executes them together...for example...
the following program:
#include <stdio.h>
int main() {
int n = 0;
printf("Gimme a number: ");
scanf ("%d", &n);
printf("/nThe number you entered was %d/n", n);
return 0;
}
has the following output:
4
Gimme a number: The number you entered was 4
Pretty normal output on any console you'll find, not just with eclipse's one
instead of:
Gimme a number: 4
The number you entered was 4
To obtain this output, you have to flush stdout before scanf'ing the number. The output is flushed either implicitely when a newline character is echoed on the console (printf("/n")) or explicitely with fflush(stdout);
to get the output you wanted use this program :
#include <stdio.h>
int main() {
int n = 0;
printf("Gimme a number: ");
fflush(stdout);
scanf ("%d", &n);
printf("/nThe number you entered was %d/n", n);
return 0;
}
相关文章推荐
- eclipse中的关于scanf和printf的输入顺序的解决办法
- 关于eclipse cdt无法正常使用printf和scanf的解决办法
- eclipse中scanf和printf的运行顺序颠倒的解决方法
- 关于eclipse端口被占用的问题解决办法
- 关于Ubuntu13.10运行eclipse时菜单无法使用的解决办法
- 关于新浪博客输入javascript语句会自动屏蔽的解决办法
- java学习之路----项目经验----eclipse 关于maven打包乱码的解决办法
- 关于VC++里cin输入不能正确结束的解决办法
- 关于AutoCompleteTextView 为什么必须输入两个字符才能出现补全提示的问题的解决办法
- 关于在运行qt的程序时提示无法定位程序输入点_ZdaPvj于动态链接库Qt5Cored.dll”的解决办法
- 关于用eclipse查看jar包中源码的解决办法
- 【吐血写此博】Fedora14下eclipse进行android开发,ibus提示没有输入窗口的 解决办法
- 关于在linux平台下用eclipse开发android,手机设备无法显示的解决办法
- 关于Xsell共享文件输入网络凭据的解决办法
- 关于AutoCompleteTextView 为什么必须输入两个字符才能出现补全提示的问题的解决办法
- 关于Eclipse提示Failed to create the java virtual machine问题解决办法
- 关于mysql数据库在输入密码后,滴的一声直接退出界面的解决办法(详细办法)
- 关于AutoCompleteTextView 为什么必须输入两个字符才能出现补全提示的问题的解决办法
- 关于Grails在输入命令出现Regression in verifier for <init> method call from inside of a branch的BUG解决办法
- 关于eclipse环境下堆空间溢出的错误解决办法