Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

compile_error

I have this compile error, not sure what it means "error : two or more data types in declaration of 'main' "

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* structure definitions */
    struct process
    {
       char proc[2];
       int D;       /* disk drives */
       int T;       /* tape drives */
       int P;       /* printer */
       int G;       /* graphical platters */
       int Dm;    /* disk drives maximum */
       int Tm;    /* tape drives maximum */
       int Pm;    /* printer maximum */
       int Gm;    /* graphical platters maximum */
    }
    /* the main client program */
    int main ()
   {
   /*
     Total Resources:
     D --- 13 Disk drives
     T --- 15 Tape drives
     P --- 12 Printer
     G --- 13 Graphical platters
    */
     
      int D = 18;
      int T = 17;
      int P = 11;
      int G = 13;
      int i = 0, j = 0, t = 0;
      int Allocated[10][4], Maximum[10][4], Need[10][4], Work[4];
      int finish[10];
      int Finish_Stack[10];
      struct process proc;
   
      FILE *pt;   /* File pointer */
      char cmd;      /* detect  user command for continue or quit */
   
      if(pt = fopen("proc.dat", "r")) == NULL)
      {
         printf("error: fopen() failed on data.txt\n");
         exit(1);    /*file open error handler */
      }
      printf("\nAllocation\tMaximum \tNeed\n");
   
      while(fscanf(pt, "%s%d%d%d%d%d%d%d%d", proc.proc, &proc.D, &proc.T,&proc.P,
                    &proc.G, &proc.Dm, &proc.Tm, &proc.Pm, &proc.Gm)!=EOF)
      {
         Allocated[i][0] = proc.D;
         Allocated[i][1] = proc.T;
         Allocated[i][2] = proc.P;
         Allocated[i][3] = proc.G;
         Maximum[i][0] = proc.Dm;
         Maximum[i][1] = proc.Tm;
         Maximum[i][2] = proc.Pm;
         Maximum[i][3] = proc.Gm;
         
        /* Calculate the Need : need[i,j]=max[i,j]-allocation[i,j] */
         Need[i][0] = Maximum[i][0] - Allocated[i][0];
         Need[i][1] = Maximum[i][1] - Allocated[i][1];
         Need[i][2] = Maximum[i][2] - Allocated[i][2];
         Need[i][3] = Maximum[i][3] - Allocated[i][3];
         D = D - Allocated[i][0];
         T = T - Allocated[i][1];
         P = P - Allocated[i][2];
         G = G - Allocated[i][3];
         
        /* set finish[i] = false for i = 1...n */
         finish[i] = 0;
         printf("\n( %d %d %d %d)\t( %d %d %d %d )\t( %d %d %d %d )\n", Allocated[i][0],
            Allocated[i][1], Allocated[i][2], Allocated[i][3], Maximum[i][0],
            Maximum[i][1], Maximum[i][2], Maximum[i][3], Need[i][0],
            Need[i][1], Need[i][2], Need[i][3]);
         i++;
      } /* end while */
   
    /* set work = available */
      printf("\nAvailable: \n");
      Work[0] = D;
      Work[1] = T;
      Work[2] = P;
      Work[3] = G;
      printf("\n%d %d %d %d\n", Work[0], Work[1], Work[2], Work[3]);
    /*-------------------------------------------------------------*/
   
      printf("\n==================================================================\n");
      i = 0;
      j = 0;
      printf("\n\npress <ENTER> to the next safe statemet\t");
      cmd = getchar();
   
      while (cmd == '\n')
      {
         if((finish[0] == 1) && (finish[1] == 1) && (finish[2] == 1) && 
         (finish[3] == 1) && (finish[4] == 1) &&(finish[5] == 1) && (finish[6] == 1) && (finish[7] == 1) && (finish[8] == 1) && (finish[9] == 1))
         {
            printf("\n\t=================================================\n");
            printf("\n\t\tAll Processes completed successfully\n");
            printf("\t\t\tWith Such a Sequence : \n\n\t\t( ");
            for(t = 0; t < 10; t++)
            {
               printf("P%d ", Finish_Stack[t]);
            }
            printf(")\n\n");
            printf("\t\t\tThe System is SAFE !\n");
            printf("\n\t=================================================\n");
            printf("\n\nProgram Terminated ... \n\n\n");
            exit(1);
         } /* if */
         for(i = 0; i < 10; i++)
         {
            printf("\nChecking Process %d", i);
            printf("\nWork ( %d %d %d %d )\n", Work[0], Work[1], Work[2], Work[3], i);
            printf("Need ( %d %d %d %d )\n", Need[i][0], Need[i][1], Need[i][2], Need[i][3]);
            if((finish[i] == 0) && (Need[i][0] <= Work[0]) && (Need[i][1] <= Work[1])
                                && (Need[i][2] <= Work[2]) && (Need[i][3] <= Work[3]))
            {
               printf("Need <= Work :\n");
               printf("So Doing Process %d\n", i);
               printf("..\n");
               printf("....\n");
               printf("..........\n");
               printf("......................\n");
           
               Work[0] = Work[0] + Allocated[i][0];
               Work[1] = Work[1] + Allocated[i][1];
               Work[2] = Work[2] + Allocated[i][2];
               Work[3] = Work[3] + Allocated[i][3];
               finish[i] = 1;
           
               printf("NOW Process %d DONE !\n\n", i);
               Finish_Stack[j] = i;
               printf("The Process have been done : ");
               for(t = 0; t < = j; t++)
               {
                  printf("P%d ", Finish_Stack[t]);
               } /* end inner for */
               
               printf("\n");
               j++;
               break;
            }
            else
            {
               if(finish[i] == 1)
               {
                  printf("This Work already been done\n");
                  printf("Jump to next process\n");
               }
               else
               {
                  printf("BECAUSE : There were Existing Need > Work\n");
                  printf("---> So, jump to next process\n");
               }
               if(i == 9)
               {
                  printf("\n\t===============================================================\n");
                  printf("\n\t\tAll Process have been checked\n");
                  printf("\t\tThere is no appropriate Process can be processing\n");
                  printf("\t\tSo There was NO Safe State so far\n");
                  printf("\n\t===============================================================\n");
                  printf("\n\nProgram Terminated ... \n\n\n");
                  exit(1);
               }
            }
         }/* end for */
         printf("\n\n\npress <ENTER> to the next safe statemet\t");
         cmd = getchar();
      } /* end while */
     
      /* close the file */
      fclose(pt);
     
      return(0);
   }



0
gbilios
Asked:
gbilios
1 Solution
 
Kent OlsenData Warehouse Architect / DBACommented:

Pretty subtle....  :)

The message means that a declaration has more than one data type.  A simple one would be:

int float SomeData;

Obviously there is a conflict here that the compiler won't be able to resolve.


In your example, the compiler tells us where the problem lies -- the typing of the main function.  If you look closely, you'll note that the token immediately preceding "main" is "int".  So far so good.

But if you back up one more token you'll see a struct{} definition.  The compiler is confused because it thinks that you're trying to apply both types (struct and int) to main().


Now the good news.  Put a ';' after the struct definition and all of this should go away.  :)



Good Luck,
Kent

0
 
gbiliosAuthor Commented:
i just realised that now.  I compiled it with gcc -ansi -Wall -o Safe Safe.c (SunC/C++ compiler) and okay.  

Thanks

0
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.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now