GCC C compiler warning “warning: control reaches…”
本问题已经有最佳答案,请猛点这里访问。
当使用"gcc-ansi-wall-pedantic conc.c"编译时,我得到以下警告我做错了什么,请帮忙。
谢谢,
conc.c: In function ‘main’:
conc.c:8:1: warning: control reaches end of non-void function [-Wreturn-type]
号
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include <stdio.h> void contract(char s1[], char s2[]); int main() { char s1[] ="abcd"; char s2[] ="zzzz"; contract(s1,s2); } void contract(char s1[], char s2[]) { char temp = 'a'; int i = 0; while (s1[i] != '\0') { temp = s1[i]; i++; } if (i != 2) { s2[0] = s1[0]; s2[1] = '-'; s2[2] = temp; } printf (" The first char string is %s the shorten one is %s ",s1,s2); } |
当使用
您的主函数没有显式返回任何内容。只需在末尾拍打一个
1 2 3 4 5 6 7 | int main() { char s1[] ="abcd"; char s2[] ="zzzz"; contract(s1,s2); return 0; /* Here! */ } |