gpt4 book ai didi

c - GCC C编译器警告 "warning: control reaches..."

转载 作者:行者123 更新时间:2023-11-30 19:54:05 25 4
gpt4 key购买 nike

使用“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]

#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 ("\n The first char string is %s \n the shorten one is %s \n",s1,s2);
}

最佳答案

您的 main 函数没有显式返回任何内容。只需在最后敲击 return 0; 就可以了:

int main()
{
char s1[] = "abcd";
char s2[] = "zzzz";
contract(s1,s2);
return 0; /* Here! */
}

关于c - GCC C编译器警告 "warning: control reaches...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40817025/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com