Solved

compile_error

Posted on 2004-10-05
2
223 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 45

Accepted Solution

by:
Kdo earned 100 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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Converting a float to a string function in c languange 10 204
Problem with MFCApp 78 346
Test against App 49 133
First character of input string truncated with scanf 3 94
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now