开发者

conflict type error previous declaration ___ was here

#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_cod开发者_运维百科e == 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 ;
    }
}

I get this error:

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

I keep getting these error messages when I compile and I'm sure I declared the prototype and its type at the beginning so I'm not sure why there a conflict in types. One of my tutors told me that it was because it was declared and to define all the types at the bottom where I called error_area but that didn't seem to work.


Just because you declared the prototype for error_area function does not mean that you are now free to omit return type and parameter types in the definition. When you define your error_area you are still supposed to specify all types explicitly

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)
{
  ...

Instead, you defined your error_area without the explicit type names. The definition was interpreted in accordance with the "old" rules, i.e. all missing types were assumed to be int, so what you defined is equivalent to

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

This is totally different from what you said in the prototype. So the compiler is telling you that your declaration contradicts your definition.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜