Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

compile_error

Posted on 2004-10-05
2
Medium Priority
?
230 Views
Last Modified: 2010-04-15
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
Comment
Question by:gbilios
2 Comments
 
LVL 46

Accepted Solution

by:
Kent Olsen earned 400 total points
ID: 12226392

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
 

Author Comment

by:gbilios
ID: 12226645
i just realised that now.  I compiled it with gcc -ansi -Wall -o Safe Safe.c (SunC/C++ compiler) and okay.  

Thanks

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question