Closed. This question is off-topic。它当前不接受答案。
想改善这个问题吗? Update the question,因此它是on-topic,用于堆栈溢出。
5年前关闭。
该程序在第3行不断给我一个意外的令牌错误,我不知道为什么?该程序是简单地阅读一个文本文件.....任何帮助,将不胜感激
然后尝试运行它
想改善这个问题吗? Update the question,因此它是on-topic,用于堆栈溢出。
5年前关闭。
该程序在第3行不断给我一个意外的令牌错误,我不知道为什么?该程序是简单地阅读一个文本文件.....任何帮助,将不胜感激
#include <stdio.h>
int main (int argc, char *argv[]) {
int c;
FILE *myfile_in, *myfile_out;
if (argv != 3) {
fprintf(stderr, "\nusage: %s infile outfile\n", *argv)
}
if ((myfile_in = fopen (*++argv, "r")) == NULL) {
fprintf(stderr, "\nmain: cannot open %s\n", *argv);
}
if ((myfile_out = fopen (*++argv, "w")) == NULL) {
fprintf(stderr, "\nmain: cannot open %s\n", *argv);
}
while ((c = getc(myfile_in)) != EOF) {
putc(c, myfile_out);
putc(c, stdout);
if (c == '\n') {
putc(c, myfile_out);
putc(c, stdout);
}
}
fclose(myfile_in);
fcolse(myfile_out);
return 0;
}
最佳答案
C代码必须在运行之前进行编译。当您尝试运行上方的源文件时,它会将其解释为Shell命令,因此第1行是注释。第一条非空白行是第3行,它对外壳没有意义-因此是错误。
要编译代码,请将其保存到文件myprog.c中并运行
gcc -o myprog myprog.c
然后尝试运行它
./myprog
08-06 03:36