• C

Compiler errors

Dear experts I have written the following code:

#include <stdio.h>

main()
{
     FILE *fp;/*creates a file pointed named fp*/
     char places[100];
     int distances[10][10];
     struct places
    {
       char places[10];
     }
     int menu;
     char userinput1[10];
     char userinput2[10];
     int cost;
     int other;
     int a;
     int b;
     struct places names[10];

/* reading in data from file*\
  do
  {
     printf("Enter file name");
     scanf("%s", places);
     fp = fopen(places,"r");
     if (fp == NULL)
     printf("File %s does not exist\n",place);
  }
  while(fp ==NULL);

  while(feof(fp) ==0)
{
   for(int i = 0; i < 10; i++)
   {
     fscanf(fp, "%s", &names[i].places);
   }
     for(int i = 0; i < 10; i ++)
     {
       for(int j = 0; j < 10; j++)
       {
         fscanf(fp, "%d", &distances[i][j]);
       }
     }

}


/* menu */

do
{
   printf("what would you like to do\n");
   printf("option 1:display mileage table");
   printf("option 2: calulate distances between points");
   printf("option 3: calulate cost of journy");
   printf("option 4: exit");
   scanf("%d", &menu);

 switch(menu)
 {
  case 1:
         display(distances, names);
         break;
  case 2:
        distance(distances, names);
        break;
  case 3:
        calc(distances,names);
        break;
  case 4:
        exit(0);
        break;
 }

}
while(menu<5 && menu > 0);

}

/* display mileage chart*/

display( distances[10][10], struct places names[10])
{
printf(" mileage chart");
printf("Burton Derby Swad Stoke Staff Lincoln Walsall Telford Cannock Warwick”)

for(int i = 0; i<10; i++)
{
  for(int j = 0; j < 10; j++)
  {
   printf("%7s",names[i].places);
   printf("%7d", distances[i][j]);

   }
}
}

/*distance between points*/
distance( distances[10][10], struct places names[10])
{

printf("Burton");
printf("Derby");
printf("Swad");
printf("Stoke");
printf("Stafford");
printf("Lincoln");
printf("Walsall");
printf("Telford");
printf("Cannock");
printf("Warwick");

printf("Enter the first point from the above list");
scanf("%s", &userinput1);

for (int i = 0; i<10; i++)
{
  if(strcmp(userinput1, names[i].places) ==0)
  a = i;
 
   else
   {
        printf("Please enter a place from the list");
   }

printf("Enter the second point from the above list");
scanf("%s", &userinput2);

for(int j = 0; j <10;j++)
{
 if(strcmp(userinput2, names[j].places) == 0)
b = j;

else
{
     printf("Please enter a place from the list");
}

printf("The distance is %d", distances[a][b]);

}

/*calculations between points*/
calc( distances[10][10], struct places names[10])
{
printf("Burton");
printf("Lincoln");
printf("Walsall");
printf("Telford");
printf("Cannock");
printf(“Warwick”);
printf("Derby");
printf("Swad");
printf("Stoke");
printf("Stafford");

printf("Enter the first point from the list");
scanf("%s", userinput1);

for (int i = 0; i <10; i++)
{
  if(strcmp(userinput1, names[i].places) == 0)
  a = i;

  else
  {
    Printf(“Please enter a point from the list”);
  }
}


printf("Enter the second point from the list");
scanf("%s", userinput2);

for(int j = 0; j < 10; j++)
{
   if(strcmp(userinput2, names[j].places) ==0)
   b = j;

   else
   {
      Printf(“Enter a point from the list”);
   }
}

if(distances[a][b] <= 100)
{
    cost = (distances[a][b] * 40)/100;
     printf("The cost is %d", cost);
}
else
{
   other = distances[a][b] - 100;
   other = other * 30;
    cost = (100 * 40) + other;
     cost = cost/100;
      printf("The cost of the journy is %d", cost);
  }
}

The following errors occur:
cc: Error: mile.c, line 87: Error parsing parameter list. Found "[" when expecting one of: ",
", ")". (notexpecting)
display( distances[10][10], struct places names[10])
------------------^
cc: Error: mile.c, line 108: Error parsing parameter list. Found "[" when expecting one of: "
,", ")". (notexpecting)
distance( distances[10][10], struct places names[10])
-------------------^
cc: Error: mile.c, line 147: Error parsing parameter list. Found "[" when expecting one of: "
,", ")". (notexpecting)
calc( distances[10][10], struct places names[10])
---------------^
cc: Error: mile.c, line 12: In this declaration, "struct" cannot be combined with "int". (typ
econflict)
  int menu;
--^
cc: Error: mile.c, line 68: In this statement, "names" is not declared. (undeclared)
       display(distances, names);

Thank you in advance for your help
Halt123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
You are missing the argument type and the return type, ie.g.

/* display mileage chart*/
void display( int distances[10][10], struct places names[10])
{
/* ...*/

/*distance between points*/
void distance( int distances[10][10], struct places names[10])
{
/* ...*/

/*calculations between points*/
void calc( int distances[10][10], struct places names[10])
{
/* ...*/
0
Halt123Author Commented:
I've changed that which has got rid of those errors, howerve its still bringing up lots of errors to do with the names varaible
cc: Error: mile.c, line 8: In this declaration, "struct" cannot be combined with "int". (type
conflict)
  int menu;
--^
cc: Error: mile.c, line 69: In this statement, "names" is not declared. (undeclared)
       display(distances, names);
--------------------------^
cc: Info: mile.c, line 88: The type "struct places" has been declared within and is limited t
o a function prototype scope.  It will not be compatible with an identical type declared in a
nother scope.  This might not be what you intended. (protoscope)
 display(int distances[10][10], struct places names[10])
--------------------------------^
cc: Error: mile.c, line 98: In this statement, "names" does not point to an object type. (nee
dptrobj)
   printf("%7s",names[i].places);
----------------^
cc: Info: mile.c, line 110: The type "struct places" has been declared within and is limited
to a function prototype scope.  It will not be compatible with an identical type declared in
another scope.  This might not be what you intended. (protoscope)
 distance(int distances[10][10], struct places names[10])
---------------------------------^
cc: Error: mile.c, line 129: In this statement, "names" does not point to an object type. (ne
edptrobj)
  if(strcmp(userinput1, names[i].places) ==0) /*userinput1 is equal to names[i].places*/
------------------------^
cc: Error: mile.c, line 143: In this statement, "names" does not point to an object type. (ne
edptrobj)
 if(strcmp(userinput2, names[j].places) == 0)
-----------------------^
cc: Info: mile.c, line 158: The type "struct places" has been declared within and is limited
to a function prototype scope.  It will not be compatible with an identical type declared in
another scope.  This might not be what you intended. (protoscope)
 calc(int distances[10][10], struct places names[10])
-----------------------------^
cc: Error: mile.c, line 176: In this statement, "names" does not point to an object type. (ne
edptrobj)
if(strcmp(userinput1, names[i].places) == 0)
----------------------^
cc: Error: mile.c, line 186: In this statement, "names" does not point to an object type. (ne
edptrobj)
if(strcmp(userinput2, names[j].places) ==0)

thank you
0
imladrisCommented:
A lot of those messages are caused by the fact that "struct places" is declare *inside* main. When other functions are declared, they cannot "see" stuff that has been done inside another function. To rectify that, lift the declaration of struct places outside/above main.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Halt123Author Commented:
the errors I get now are:

cc: Error: mile.c, line 8: In this declaration, "struct" cannot be combined with "int". (type
conflict)
  int menu;
--^
cc: Error: mile.c, line 98: In this statement, "names" does not point to an object type. (nee
dptrobj)
   printf("%7s",names[i].places);
----------------^
cc: Error: mile.c, line 129: In this statement, "names" does not point to an object type. (ne
edptrobj)
  if(strcmp(userinput1, names[i].places) ==0) /*userinput1 is equal to names[i].places*/
------------------------^
cc: Error: mile.c, line 143: In this statement, "names" does not point to an object type. (ne
edptrobj)
 if(strcmp(userinput2, names[j].places) == 0)
-----------------------^
cc: Error: mile.c, line 176: In this statement, "names" does not point to an object type. (ne
edptrobj)
if(strcmp(userinput1, names[i].places) == 0)
----------------------^
cc: Error: mile.c, line 186: In this statement, "names" does not point to an object type. (ne
edptrobj)
if(strcmp(userinput2, names[j].places) ==0)
----------------------^
cc: Error: mile.c, line 16: The type of the tentatively-defined variable "names" is incomplet
e at the end of the compilation unit. (incomptent)
struct places names[10];

thank you for ur help
0
imladrisCommented:
The first error was originally cause by the fact that the definition for "struct places" was not ended with a semi-colon. However, I'm puzzled as to why that would still show up as tripping on "int menu". Did you not lift struct places out of main? Did you take int menu with it?

I don't have an explanation for the names errors, off hand. The error hing (needptrobj) appears to mean "need pointer object". But names seems to be one. The problem may be connected to the places declaration/definition missing the semi-colon.

Give it another whirl; think about the errors you're getting. If you have more questions, please post the code you currently have.
0
Halt123Author Commented:
Its still bringing up the errors

the code is:
#include <stdio.h>
char places[100];
     int distances[10][10];
     struct places;
    {
       char places[10];
     }
     int menu;
     char userinput1[10];
     char userinput2[10];
     int cost;
     int other;
     int a;
     int b;
     struct places names[10];

main()
{
     FILE *fp;/*creates a file pointed named fp*/
     
/* reading in data from file*\
  do
  {
     printf("Enter file name");
     scanf("%s", places);
     fp = fopen(places,"r");
     if (fp == NULL)
     printf("File %s does not exist\n",place);
  }
  while(fp ==NULL);

  while(feof(fp) ==0)
{
   for(int i = 0; i < 10; i++)
   {
     fscanf(fp, "%s", &names[i].places);
   }
     for(int i = 0; i < 10; i ++)
     {
       for(int j = 0; j < 10; j++)
       {
         fscanf(fp, "%d", &distances[i][j]);
       }
     }

}


/* menu */

do
{
   printf("what would you like to do\n");
   printf("option 1:display mileage table");
   printf("option 2: calulate distances between points");
   printf("option 3: calulate cost of journy");
   printf("option 4: exit");
   scanf("%d", &menu);

 switch(menu)
 {
  case 1:
         display(distances, names);
         break;
  case 2:
        distance(distances, names);
        break;
  case 3:
        calc(distances,names);
        break;
  case 4:
        exit(0);
        break;
 }

}
while(menu<5 && menu > 0);

}

/* display mileage chart*/

display( distances[10][10], struct places names[10])
{
printf(" mileage chart");
printf("Burton Derby Swad Stoke Staff Lincoln Walsall Telford Cannock Warwick”)

for(int i = 0; i<10; i++)
{
  for(int j = 0; j < 10; j++)
  {
   printf("%7s",names[i].places);
   printf("%7d", distances[i][j]);

   }
}
}

/*distance between points*/
distance( distances[10][10], struct places names[10])
{

printf("Burton");
printf("Derby");
printf("Swad");
printf("Stoke");
printf("Stafford");
printf("Lincoln");
printf("Walsall");
printf("Telford");
printf("Cannock");
printf("Warwick");

printf("Enter the first point from the above list");
scanf("%s", &userinput1);

for (int i = 0; i<10; i++)
{
  if(strcmp(userinput1, names[i].places) ==0)
  a = i;
 
   else
   {
        printf("Please enter a place from the list");
   }

printf("Enter the second point from the above list");
scanf("%s", &userinput2);

for(int j = 0; j <10;j++)
{
 if(strcmp(userinput2, names[j].places) == 0)
b = j;

else
{
     printf("Please enter a place from the list");
}

printf("The distance is %d", distances[a][b]);

}

/*calculations between points*/
calc( distances[10][10], struct places names[10])
{
printf("Burton");
printf("Lincoln");
printf("Walsall");
printf("Telford");
printf("Cannock");
printf(“Warwick”);
printf("Derby");
printf("Swad");
printf("Stoke");
printf("Stafford");

printf("Enter the first point from the list");
scanf("%s", userinput1);

for (int i = 0; i <10; i++)
{
  if(strcmp(userinput1, names[i].places) == 0)
  a = i;

  else
  {
    Printf(“Please enter a point from the list”);
  }
}


printf("Enter the second point from the list");
scanf("%s", userinput2);

for(int j = 0; j < 10; j++)
{
   if(strcmp(userinput2, names[j].places) ==0)
   b = j;

   else
   {
      Printf(“Enter a point from the list”);
   }
}

if(distances[a][b] <= 100)
{
    cost = (distances[a][b] * 40)/100;
     printf("The cost is %d", cost);
}
else
{
   other = distances[a][b] - 100;
   other = other * 30;
    cost = (100 * 40) + other;
     cost = cost/100;
      printf("The cost of the journy is %d", cost);
  }
}




0
Halt123Author Commented:
I've just found where the error were

thank you for your help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.