Gcc似乎没有让我的scanf正确,但Visual Studio确实如此,这有什么不对? [英] Gcc doesn't seem to get my scanf right, but Visual Studio does, what's wrong?

查看:90
本文介绍了Gcc似乎没有让我的scanf正确,但Visual Studio确实如此,这有什么不对?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我实际上认为我的编程技巧有问题。但是在使用Visual Studio编译相同的代码之后,它起作用了。所以这里的代码似乎没有与gcc编译器一起工作,但它们确实编译。注意我正在使用Cygwin 3.4.4版本的gcc和4.5.1版本的gcc来自MinGW。

First I actually thought there was something wrong with my programming skills. But after I compiled the same code using Visual Studio, it worked. So here''s the code that doesn''t seem to be working right with gcc compilers, but they do compile. Note I''m using the Cygwin 3.4.4 version of gcc and 4.5.1 version of gcc from MinGW.

展开 | 选择 | 换行 | 行号

推荐答案

也许unix [Cygwin]和DOS [Visual Studio]之间的行终止(LF vs CR-LF)的差异正在抓住你。你应该测试scanf的返回码。
Perhaps the difference in line termination (LF vs CR-LF) between unix [Cygwin] and DOS [Visual Studio] is catching you. You should be testing the return code from scanf.


不,看起来像一个bug。提交给gcc bugzilla。 错误46908



A
No, looks like a bug. Submitting to gcc bugzilla. Bug 46908


A


谢谢大家!但我想我现在已经找到了问题的答案。据回复我的电子邮件的人说,这是因为gcc在键盘缓冲区中保留了一个空间。如果第二个输入始终为0,你可以判断同样的事情是否会再次发生。他说我应该尝试使用以下代码分隔的代码:

Thanks guys! But I think I have found the answer to my problem now. According to someone who replied to my email it was because gcc was keeping a space in the keyboard buffer. And you can tell if the same thing''s happening again if the second input is always 0. He said I should try to use the following code separated by a space instead:

展开 | 选择 | < span class =codeLinkonclick =WordWrap(this);> Wrap | 行号


这篇关于Gcc似乎没有让我的scanf正确,但Visual Studio确实如此,这有什么不对?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆