为什么从K&放一些code,R不在code工作:块? [英] Why is some code from K&R not working in Code:Blocks?
问题描述
一些在K&放大器的例子; R不要在code工作:块时,我准确键入他们。
例如,这个程序:
Some of the examples in K&R don't work in Code:Blocks when I type them exactly. For example, this program:
#include <stdio.h>
main()
{
long nc;
nc = 0;
while (getchar() != EOF)
++nc;
printf("%ld\n", nc);
}
当我键入此code和运行它,程序要么冻结或没有做任何事情,当我preSS进入。
When I type this code and run it, the program either freezes or doesn't do anything when I press enter.
下面的程序做同样的事(计数字符串中的字符)和它的作品。
The program below does the same thing (count characters in a string) and it works.
#include <stdio.h>
int main()
{
char s[1000];
int i;
scanf("%s",s);
for(i=0; s[i]!='\0'; ++i);
printf("Length of string: %d",i);
return 0;
}
我失去了一些东西在这里?因为K&放大器已丙改变; R第2版还是我做错了什么。
Am I missing something here? Has C been changed since K&R 2nd Edition or am I doing something wrong?
推荐答案
在preSS输入,发送 \\ n
为标准输入流(并刷新其他数据到标准输入
,如果有的话)。这个字符( \\ n
)是的不的一样 EOF
。要发送 EOF
,preSS下面的键组合:
When you press enter, you send \n
into the standard input stream(and flushes other data into the stdin
,if any). This character(\n
) is not the same as EOF
. To send EOF
, press following keys combinations:
- <大骨节病> CTRL 骨节病> <大骨节病>以Z 骨节病>然后<大骨节病>输入骨节病>在Windows中。
- <大骨节病> CTRL 骨节病> <大骨节病> D 骨节病>中的Unix / Linux / OSX
- CTRL Z and then Enter in Windows.
- CTRL D in Unix/Linux/OSX
这篇关于为什么从K&放一些code,R不在code工作:块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!