所以我是C语言的初学者,我一直在关注Primer Plus 6th Edition。在运行程序时,我发现确实有些奇怪,例如,编译器无法正常工作。
int main(){ one_three(); getchar(); return 0; } void one_three(void){ printf("one\n"); two(); printf("three"); } void two(void){ printf("two\n"); }
这是我的代码,因为没有函数原型声明并且不包括头文件,所以有很多错误,但是有些输出仅通过发出警告来产生,我不认为这应该发生]]
输出为:
review1.c: In function 'main': review1.c:2:5: warning: implicit declaration of function 'one_three' [-Wimplicit-function-declaration] 2 | one_three(); | ^~~~~~~~~ review1.c:3:5: warning: implicit declaration of function 'getchar' [-Wimplicit-function-declaration] 3 | getchar(); | ^~~~~~~ review1.c:1:1: note: 'getchar' is defined in header '<stdio.h>'; did you forget to '#include <stdio.h>'? +++ |+#include <stdio.h> 1 | int main(){ review1.c: At top level: review1.c:7:6: warning: conflicting types for 'one_three' 7 | void one_three(void){ | ^~~~~~~~~ review1.c:2:5: note: previous implicit declaration of 'one_three' was here 2 | one_three(); | ^~~~~~~~~ review1.c: In function 'one_three': review1.c:8:5: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration] 8 | printf("one\n"); | ^~~~~~ review1.c:8:5: warning: incompatible implicit declaration of built-in function 'printf' review1.c:8:5: note: include '<stdio.h>' or provide a declaration of 'printf' review1.c:9:5: warning: implicit declaration of function 'two' [-Wimplicit-function-declaration] 9 | two(); | ^~~ review1.c: At top level: review1.c:13:6: warning: conflicting types for 'two' 13 | void two(void){ | ^~~ review1.c:9:5: note: previous implicit declaration of 'two' was here 9 | two(); | ^~~ review1.c: In function 'two': review1.c:14:5: warning: incompatible implicit declaration of built-in function 'printf' 14 | printf("two\n"); | ^~~~~~ review1.c:14:5: note: include '<stdio.h>' or provide a declaration of 'printf' one two three
那些最后三行“一”二三是输出请帮助,我正在使用此编译器
我希望它在需要时会输出错误,并且本身不会添加任何东西,这样我就可以从我的错误中学到使用带有扩展名的Visual Studio代码:Microsoft的C / C ++,代码运行器
所以我是C语言的初学者,我一直在关注Primer Plus 6th Edition。在运行程序时,我发现确实有些奇怪,编译器无法正常运行,因为...
您在顶部缺少函数原型:
void two(void);
void one_three(void);
int main(){
one_three();
getchar();
return 0;
}
void one_three(void){
printf("one\n");
two();
printf("three");
}
void two(void){
printf("two\n");
}
您需要在使用它们的函数上方声明要在函数中使用的方法。如果将这些函数重新排序为2,则将one_three排序为main。应该可以。