Thread: C Compiling error

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    11

    C Compiling error

    I am using a GCC compiler and getting the following errors:
    prog1.c: In function `main':
    prog1.c:57: error: missing terminating " character
    prog1.c:58: error: syntax error before ':' token
    prog1.c:58: error: missing terminating " character



    Code:
    #include<stdio.h>
    
    void FIFO(char [],char [],int,int);
    void lru(char [],char [],int,int);
    void opt(char [],char [],int,int);
    
    
    int main()
    {
       int ch,YN=1,i,l,f;
       char F[10],s[25];
       clrscr();
       //system("clear");
       printf("\n\n\tEnter the no of empty frames: ");
       scanf("%d",&f);
       printf("\n\n\tEnter the length of the string: ");
       scanf("%d",&l);
       printf("\n\n\tEnter the string: ");
       scanf("%s",s);
       for(i=0;i<f;i++)
         F[i]=-1;
          do
        {
         // system("clear");
          printf("\n\n\t*********** MENU ***********");
          printf("\n\n\t1:FIFO\n\n\t2:LRU\n\n\t3:OPT\n\n\t4:EXIT");
          printf("\n\n\tEnter your choice: ");
          scanf("%d",&ch);
          //system("clear");
          switch(ch)
           {
          case 1:
              for(i=0;i<f;i++)
               {
                 F[i]=-1;
               }
    
    
              FIFO(s,F,l,f);
              break;
          case 2:
              for(i=0;i<f;i++)
               {
                 F[i]=-1;
               }
              lru(s,F,l,f);
              break;
          case 3:
              for(i=0;i<f;i++)
               {
                 F[i]=-1;
               }
    
    
              opt(s,F,l,f);
              break;
          case 4:
              exit(0);
           }
          printf("\n\n\tDo u want to continue IF YES PRESS 1\n\n\tIF NO PRESS 0 : ");
          scanf("%d", &YN);
        }while(YN==1);return(0);
    }
    
    
    //FIFO
    void FIFO(char s[],char F[],int l,int f)
    {
       int i,j=0,k,flag=0,cnt=0;
       printf("\n\tPAGE\t    FRAMES\t  FAULTS");
       for(i=0;i<l;i++)
        {
           for(k=0;k<f;k++)
        {
          if(F[k]==s[i])
            flag=1;
        }
    
    
           if(flag==0)
        {
          printf("\n\t%c\t",s[i]);
          F[j]=s[i];
          j++;
    
    
          for(k=0;k<f;k++)
           {
            printf("   %c",F[k]);
           }
          printf("\tPage-fault%d",cnt);
          cnt++;
        }
    
    
           else
        {
          flag=0;
          printf("\n\t%c\t",s[i]);
          for(k=0;k<f;k++)
           {
            printf("   %c",F[k]);
           }
    
    
          printf("\tNo page-fault");
        }
           if(j==f)
        j=0;
        }
    
    
    }
    
    
    
    
    //LRU
    void lru(char s[],char F[],int l,int f)
    {
       int i,j=0,k,m,flag=0,cnt=0,top=0;
       printf("\n\tPAGE\t    FRAMES\t  FAULTS");
       for(i=0;i<l;i++)
        {
           for(k=0;k<f;k++)
        {
          if(F[k]==s[i])
           {
            flag=1;
             break;
           }
        }
    
    
           printf("\n\t%c\t",s[i]);
           if(j!=f && flag!=1)
        {
          F[top]=s[i];
          j++;
    
    
          if(j!=f)
           top++;
        }
           else
        {
           if(flag!=1)
            {
              for(k=0;k<top;k++)
               {
            F[k]=F[k+1];
               }
    
    
               F[top]=s[i];
            }
           if(flag==1)
            {
               for(m=k;m<top;m++)
               {
            F[m]=F[m+1];
               }
    
    
               F[top]=s[i];
            }
        }
           for(k=0;k<f;k++)
        {
         printf("   %c",F[k]);
        }
    
    
           if(flag==0)
        {
          printf("\tPage-fault%d",cnt);
          cnt++;
        }
           else
         printf("\tNo page fault");
           flag=0;
        }
    
    
    }
    
    
    
    
    //optimal
    void opt(char s[],char F[],int l,int f)
    {
       int i,j=0,k,m,flag=0,cnt=0,temp[10];
    
    
       printf("\n\tPAGE\t    FRAMES\t  FAULTS");
       for(i=0;i<10;i++)
         temp[i]=0;
    
    
       for(i=0;i<f;i++)
         F[i]=-1;
    
    
       for(i=0;i<l;i++)
        {
           for(k=0;k<f;k++)
        {
          if(F[k]==s[i])
            flag=1;
        }
    
    
           if(j!=f && flag==0)
        {
          F[j]=s[i];
          j++;
        }
    
    
           else if(flag==0)
        {
           for(m=0;m<f;m++)
            {
              for(k=i+1;k<l;k++)
               {
              if(F[m]!=s[k])
               {
                 temp[m]=temp[m]+1;
               }
              else
               break;
               }
            }
           m=0;
           for(k=0;k<f;k++)
            {
               if(temp[k]>temp[m])
            {
              m=k;
            }
            }
    
    
           F[m]=s[i];
        }
    
    
           printf("\n\t%c\t",s[i]);
           for(k=0;k<f;k++)
        {
           printf("  %c",F[k]);
        }
           if(flag==0)
        {
          printf("\tPage-fault %d",cnt);
          cnt++;
        }
           else
         printf("\tNo Page-fault");
           flag=0;
    
    
           for(k=0;k<10;k++)
         temp[k]=0;
         }
    }

  2. #2
    Registered User
    Join Date
    Sep 2012
    Posts
    11
    I have counted all my
    Code:
    { and }
    to ensure there was the same number but still am stumped. thanks in advance all!

  3. #3
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Please provide all of the compiler errors. Copy-paste them exactly, including line numbers. It also wouldn't hurt if you provided the exact command you used to compile. E.g.
    Code:
    $ gcc -Wall -g -std=c99 -pedantic  -lm -lpthread -lefence  fifo.c   -o fifo
    fifo.c: In function ‘main’:
    fifo.c:12: warning: implicit declaration of function ‘clrscr’
    fifo.c:58: warning: implicit declaration of function ‘exit’
    fifo.c:58: warning: incompatible implicit declaration of built-in function ‘exit’
    /tmp/cc3srhKe.o: In function `main':
    /home/tyco/sandbox/cprogramming/fifo.c:12: undefined reference to `clrscr'
    collect2: ld returned 1 exit status
    make: *** [fifo] Error 1

  4. #4
    Registered User
    Join Date
    Sep 2012
    Posts
    11
    Code:
    Polaris> gcc -o prog1 prog1.cprog1.c: In function `main':
    prog1.c:57: error: missing terminating " character
    prog1.c:58: error: syntax error before ':' token
    prog1.c:58: error: missing terminating " character
    Last edited by jimmyn; 09-28-2012 at 05:07 PM.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Hmm...I don't get any such error, as you can see from the output I provided in post #3. Also, I think your line numbers in what you posted are a bit different from the code you posted.

    Are lines 57-58 in your program the following two?
    Code:
    printf("\n\n\tDo u want to continue IF YES PRESS 1\n\n\tIF NO PRESS 0 : ");
    scanf("%d", &YN);
    Look for a missing " somewhere (an editor that provides syntax highlighting is indespensible for things like this). Alternatively, copy-paste the code form the forum here into your editor, save the file and try recompiling. The code here seems to be fine (except for using the non-standard clrscr, and you need to #include <stdlib.h> if you want to use the exit function).

  6. #6
    Registered User
    Join Date
    Sep 2012
    Posts
    11
    Those are the two lines my compiler is counting as 57 and 58

  7. #7
    Registered User
    Join Date
    Sep 2012
    Posts
    11
    Still getting that error! Ugh!

  8. #8
    Registered User
    Join Date
    Sep 2012
    Posts
    11
    OK now i have C-Free to test (which is WAY nicer than darn school way) but i am getting a 'clrscr" was not declared in this scope. I have added:
    Code:
    #include <stdlib.h> 
    #include <conio.h>

  9. #9
    Registered User
    Join Date
    Sep 2012
    Posts
    11
    got it! Took out the <conio.h> and put in:
    system("cls"); where the clrscr was

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error during compiling
    By altaf in forum C Programming
    Replies: 4
    Last Post: 06-17-2010, 07:59 AM
  2. compiling error!
    By Nora in forum C++ Programming
    Replies: 3
    Last Post: 12-25-2006, 05:34 AM
  3. Compiling error (Maybe a syntax error)
    By davidvoyage200 in forum C++ Programming
    Replies: 6
    Last Post: 03-27-2003, 10:09 PM
  4. Very odd compiling error...
    By Captain Penguin in forum C++ Programming
    Replies: 5
    Last Post: 09-30-2002, 09:06 PM
  5. I have a compiling error...
    By DarkSFK in forum C++ Programming
    Replies: 7
    Last Post: 08-03-2002, 08:46 PM