#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
我在编译时不断收到这些错误消息,并且我确定我在开始时声明了原型及其类型,所以我不确定为什么会出现类型冲突。 我的一位导师告诉我,这是因为它被声明并定义了底部的所有类型,我称之为error_area,但这似乎不起作用。
答案 0 :(得分:1)
仅仅因为您声明error_area
函数的原型并不意味着您现在可以在定义中省略返回类型和参数类型。当你定义你的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 */
{
...
这与您在原型中所说的完全不同。所以编译器告诉你你的声明与你的定义相矛盾。