您好我正在教自己C并通过K&R书,我遇到了一些麻烦(我正在运行OS X).这是第1.5.1节"文件复制",它应该将一个字符作为输入,然后输出该字符.这是代码:
#include <stdio.h>
/* -- Copy input to output -- */
int main(void)
{
int c;
c = getchar();
while ( c != EOF ) {
putchar(c);
c = getchar;
}
}
Run Code Online (Sandbox Code Playgroud)
所以,我认为我的问题不在于代码本身,而在于编译和运行.首先,在编译时我得到以下错误
/Volumes/Goliath/Dropbox/C programs/prog1_5_1.c: In function ‘main’:
/Volumes/Goliath/Dropbox/C programs/prog1_5_1.c:12: warning: assignment makes integer from pointer without a cast
/Volumes/Goliath/Dropbox/C programs/prog1_5_1.c:16: warning: control reaches end of non-void function
Run Code Online (Sandbox Code Playgroud)
然后当我运行输出文件(在终端中)它有一个小空间,然后当我输入一个字母时,说我输入
一个
然后我点击Return
我得到一个新的一行.如果我然后点击一个新密钥,屏幕就会开始变得疯狂,并在整个地方出现问号.
我不确定我是否有多大意义,但我发现这是一个奇怪的问题.非常感谢你提前
第二项任务应该是c = getchar();.通过省略括号,您将指定getchar函数的地址c,这非常不符合您的要求.
此外,在main你需要线return 0;或类似的结束时,为了摆脱"控制到达无效功能的结束"警告.
| 归档时间: |
|
| 查看次数: |
2780 次 |
| 最近记录: |