gpt4 book ai didi

冲突类型错误之前的声明 ___ 在这里

转载 作者:行者123 更新时间:2023-11-30 16:02:36 24 4
gpt4 key购买 nike

#define TRIP 6
#include <stdio.h>

char error_area(char area_code, char S, char M, char L, char N, char P, char K, char R, char C, char U, char W, char O, char T, char F);

int main(void)
{
char area_code, S, M, L, N, P, K, R, C, U, W, O, T, F, checkB, travelarea[TRIP];

printf("Please select from the following that best describes your destination:\n"); /*area code input*/
printf("S Small city - population under 50,000\n"); /*Choices for area code*/
printf("M Medium city - population between 50,000 and 500,000\n");
printf("L Large city - pop. over 500,000\n");
printf("N Natural formation like a mountain, a lake, a cave, a geyser, a fjord, a canyon, etc.\n");
printf("P Designated park or reserve such as a wildlife refuge, a national park, a bioreserve, or a protected marine area\n");
printf("K Man made landmark like the Great Wall of China, the Taj Mahal, or Stonehenge\n");
printf("R State or province or region of a country\n");
printf("C Whole country\n");
printf("U Multiple countries like traveling through Europe\n");
printf("W Ocean voyage\n");
printf("O Any other type of destination - such as visiting the sites of the seven wonders of the world\n");
printf("Please enter the Area Letter code:");
scanf("%c", &area_code);

checkB = error_area(area_code, S, M, L, N, P, K, R, C, U, W, O, T, F);
while (checkB == F) /*error loop for error area code*/
{
printf("Please re-enter a valid area_code:");
scanf("%c", &area_code);
checkB = error_area(area_code, S, M, L, N, P, K, R, C, U, W, O, T, F);
if (checkB == T)
{travelarea[0]=area_code;}
}

}

error_area(area_code, S, M, L, N, P, K, R, C, U, W, O, T, F) /*area code error check*/
{

if ( (area_code == S) || (area_code == M) || (area_code == L) ||(area_code == N) ||(area_code == P) ||(area_code == K) || (area_code == R) ||(area_code == C) || (area_code == U) || (area_code == W) || (area_code == O))
{
return T;
}
else
{
printf("Area code is invalid. (Please make sure code is capitalize)\n");

return F ;
}
}

我收到此错误:

test2.c:40: error: conflicting types for âerror_areaâ
test2.c:5: error: previous declaration of âerror_areaâ was here

我在编译时不断收到这些错误消息,并且我确定我在开始时声明了原型(prototype)及其类型,所以我不确定为什么类型存在冲突。我的一位导师告诉我,这是因为它是在我调用 error_area 的底部声明并定义所有类型的,但这似乎不起作用。

最佳答案

仅仅因为您声明了 error_area 函数的原型(prototype),并不意味着您现在可以在定义中随意省略返回类型和参数类型。当您定义您的error_area时,您仍然应该显式指定所有类型

char error_area(char area_code, char S, char M, char L, char N, char P, char K, char R, char C, char U, char W, char O, char T, char F)
{
...

相反,您在没有显式类型名称的情况下定义了 error_area。该定义是根据“旧”规则解释的,即所有缺失的类型都假定为 int,因此您定义的内容相当于

int error_area(int area_code, int S, ... /* and so on */
{
...

这和你在原型(prototype)中所说的完全不同。因此编译器告诉您您的声明与您的定义相矛盾。

关于冲突类型错误之前的声明 ___ 在这里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5108478/

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