我想学习一些C语言,并选择使用本书“SAMS在21天内自学C”。 (顺便说一句,有什么好的C书?这是我的第三本书!我总是会得到坏的或破碎的代码,它应该在我的学习过程中发挥作用,并在它不存在的时候撞到墙上!:-() 。 可悲的是,我在这下面的代码,我只是要输入和运行运行打字很顺利,但运行......嗯,不是那么好 编译器给了我这行错误:Error_handler ...什么?
{
printf ("Printer busy or disconnected\n"); error_handler; }
,当我尝试运行此代码,因为我非常新手,当涉及到C代码,我不知道在所有做什么,当编辑器返回错误信息是这样的:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .clean-conf
rm -f -r build/Debug
rm -f dist/Debug/GNU-MacOSX/type_and_run
CLEAN SUCCESSFUL (total time: 158ms)
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-MacOSX/type_and_run
mkdir -p build/Debug/GNU-MacOSX
rm -f build/Debug/GNU-MacOSX/Type and run 1.o.d
gcc -c -g -MMD -MP -MF build/Debug/GNU-MacOSX/Type and run 1.o.d -o build/Debug
/GNU-MacOSX/Type\ and\ run\ 1.o Type\ and\ run\ 1.c
i686-apple-darwin10-gcc-4.2.1: and: No such file or directory
i686-apple-darwin10-gcc-4.2.1: run: No such file or directory
i686-apple-darwin10-gcc-4.2.1: 1.o.d: No such file or directory
Type and run 1.c: In function 'do_heading':
Type and run 1.c:54: error: 'error_handler' undeclared (first use in this function)
Type and run 1.c:54: error: (Each undeclared identifier is reported only once
Type and run 1.c:54: error: for each function it appears in.)
make[2]: *** [build/Debug/GNU-MacOSX/Type and run 1.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 158ms)
我能理解的是“error_handler”未声明,并且它似乎不是库函数。叹!
所以说简而言之,有什么我可以做的修改代码,以便它可以按预期工作,我可以继续前进?
或者我应该把这本书放在一堆关于C的无用书中?
这里是它的全长代码:
void do_heading(char *filename);
int line = 0, page = 0;
int main(int argv, char *argc[])
{
char buffer[256];
FILE *fp;
if (argv < 2)
{
fprintf(stderr, "\nProper Usage is: ");
fprintf(stderr, "\n\nprint_it filename.ext\n");
return (1);
}
if ((fp = fopen(argc[1], "r")) == NULL)
{
fprintf(stderr, "Error opening file, %s!", argc[1]);
return (1);
}
page = 0;
line = 1;
do_heading(argc[1]);
while(fgets(buffer, 256, fp) != NULL)
{
if(line % 55 == 0)
do_heading(argc[1]);
fprintf(stdout , "%4d:\t%s", line++, buffer);
}
fprintf(stdout , "\f");
fclose(fp);
return 0;
}
void do_heading(char *filename)
{
page++;
if (page > 1)
fprintf(stdout , "\f");
fprintf(stdout, "Page: %d, %s\n\n", page, filename);
if ((stdout = fopen("PRT:","w")) == NULL) {
printf ("Printer busy or disconnected\n"); error_handler; }
}
“int argv”and“char * argc []”..really?!!! – 2011-12-20 17:17:41
这本书说的是什么! :-S – 2011-12-20 17:19:28
但是没有其他的代码没有问题,除了这一行: { printf(“Printer busy or disconnected \ n”); error_handler; } – 2011-12-20 17:20:35