Thread: Parse Error Before String Constant?

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    2

    Parse Error Before String Constant?

    Code:
    #include <ctype.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <math.h>
    
    int main(void)
    {
          int iLongDeg, iLongMin, iLongSec, iLatDeg, iLatMin, iLatSec, iFlag;
          int iError=0, iCtr=1, iFirst=1, iTotal=1;
          float fSmallDist=0, fLargeDist=0, fAvg=0, fAvgTotal=0;
          float pi = atan2(1,1)*4, fDecDeg, fRag, fDist, a1, a2,b1,b2;
          char cLongD, cLatD;
    /*
          int rc, longitude_1;
          printf("\nFirst longitude : ");
          rc = scanf("%d", &longitude_1);
    */
          while(!iFlag == 0){
              iError=0;
              printf("\nLongitude (DDDMMSS): ");
              iFlag = scanf("%3d%2d%2d", &iLongDeg, &iLongMin, &iLongSec);
    
              if (Err_Check(iLongDeg, iLongMin, iLongSec) != 0){
                  iError=1;
                  while(iError == 1){
                       printf("Reenter Longitude (DDDMMSS): ");
                       iFlag = scanf("%3d%2d%2d", &iLongDeg, &iLongMin, &iLongSec);
                       if (Err_Check(iLongDeg, iLongMin, iLongSec) != 0){
                          iError=1;
                       }
                       else { iError=0; }
                  }
              }
    
              printf("Direction (W or E): ");
              scanf("%c", &cLongD);
    
              if (cLongD != 'w' || cLongD != 'W' || cLongD != 'e' || cLongD != 'E'){
                  iError=1;
                  while(iError == 1){
                       print("Reenter Direction (W or E): ");
                       scanf("%c", cLongD);
                       if (cLongD != 'w' || cLongD != 'W' || cLongD != 'e' || cLongD != 'E'){
                           iError=1;
                       }
                       else{
                           iError=0;
                       }
                  }
              }
    
              if(cLongD == 'w' || 'W') { iLongDeg = iLongDeg * -1; }
    
              printf("\nLattitude (DDDMMSS): ");
              iFlag = scanf("%3d%2d%2d", &iLatDeg, &iLatMin, &iLatSec);
              if (Err_Check(iLatDeg, iLatMin, iLatSec) != 0){
                  iError=1;
                  while(iError == 1){
                       printf("Reenter Lattitude (DDDMMSS): ");
                       iFlag = scanf("%3d%2d%2d", &iLatDeg, &iLatMin, &iLatSec);
                       if (Err_Check(iLatDeg, iLatMin, iLatSec) != 0){
                          iError=1;
                       }
                       else { iError=0; }
                  }
              }
              printf("Direction (N or S): ");
              scanf("%c", &cLatD);
              if (cLatD != 'n' || cLatD != 'N' || cLatD != 's' || cLatD != 'S'){
                  iError=1;
                  while(iError == 1){
                       print("Reenter Direction (N or S): ");
                       scanf("%c", cLatD);
                       if (cLatD != 'n' || cLatD != 'N' || cLatD != 's' || cLatD != 'S'){
                           iError=1;
                       }
                       else{
                           iError=0;
                       }
                  }
              }
    
            if(cLatD == 'S' || 's') { iLatDeg = iLatDeg * -1; }
    
            if(iCtr == 1)
            {
              fDecDeg = iLatDeg + (iLatMin + iLatSec / 60) / 60;
              a1 = fDecDeg * (pi/180);
    
              fDecDeg = iLongDeg + (iLongMin + iLongSec / 60) / 60;
              b1 = fDecDeg * (pi/180);
    
              iCtr++;
            }
            else if (iCtr == 2){
              fDecDeg = iLatDeg + (iLatMin + iLatSec / 60) / 60;
              a2 = fDecDeg * (pi/180);
    
              fDecDeg = iLongDeg + (iLongMin + iLongSec / 60) / 60;
              b2 = fDecDeg * (pi/180);
    
              fDist = acos(cos(a1)*cos(b1)*cos(a2)*cos(b2) + cos(a1)*sin(b1)*cos(a2)*sin(b2) + sin(a1)*sin(a2)) * 6378;
    
              iCtr--;
    
              if(iFirst == 1){
                 iFirst++;
                 iTotal++;
                 fSmallDist = fDist;
                 fLargeDist = fDist;
                 fAvg = fDist;
                 fAvgTotal+=fDist;
              }
              else
                  if( fSmallDist > fDist ){
                     fSmallDist = fDist;
                  }
                  if(fLargeDist < fDist){
                     fLargeDist = fDist;
                  }
                  iTotal++;
                  fAvgTotal+=fDist;
              }
    
              printf("\n\n Distance (in KM): %10.2f", fDist);
              system("PAUSE");
              system("CLEAR");
            }
          }
    
    //**************************** These Lines have the Errors added line numbers to help out.
    131   printf("\n\nSummary of Data Processed (in km)");
    132   printf("\n\nSmallest Distance %10.2f", fSmallDist);
    133   printf("\n Largest Distance %10.2f", fLargeDist);
    134      fAvg = fAvgTotal / iTotal;
    135      printf("\n Average Distance %10.2f", fAvg);
    136
    137      system("PAUSE");
    //**************************** These Lines have the Errors ^
          return 0;
    }
    
    int Err_Check(int iDeg, int iMin, int iSec)
    {
        int iErr=0;
    
        if(iDeg > 180 || iDeg < 0){ iErr+=1; }
        if(iMin > 60 || iMin < 0) { iErr+=2; }
        if(iSec > 60 || iSec < 0) { iErr+=5; }
    //    if(strlen(iDeg) > 3 || strlen(iMin) > 2 || strlen(iSec) > 2){
    //       printf("Error: Invalid Data");
    //       iErr=8;
    //    }else{
            if(iErr == 1) { printf("Error: You have entered invalid degrees.\n"); }
            if(iErr == 2) { printf("Error: You have entered invalid minutes.\n"); }
            if(iErr == 5) { printf("Error: You have entered invalid seconds.\n"); }
            if(iErr == 3) { printf("Error: You have entered invalid degrees and minutes.\n"); }
            if(iErr == 6) { printf("Error: You have entered invalid degrees and seconds.\n"); }
            if(iErr == 7) { printf("Error: You have entered invalid minutes and seconds.\n"); }
            if(iErr == 8) { printf("Error: You have entered invalid degrees, minutes, and seconds.\n"); }
    //     }
    
        return iErr;
    }
    131 c:\school\assign~1.c parse error before string constant
    131 c:\school\assign~1.c warning: data definition has no type or storage class
    132c:\school\assign~1.c parse error before string constant
    132c:\school\assign~1.c warning: data definition has no type or storage class
    133c:\school\assign~1.c parse error before string constant
    133c:\school\assign~1.c warning: data definition has no type or storage class
    134c:\school\assign~1.c parse error before string constant
    134c:\school\assign~1.c warning: data definition has no type or storage class
    135c:\school\assign~1.c parse error before string constant
    135c:\school\assign~1.c warning: data definition has no type or storage class
    137c:\school\assign~1.c parse error before string constant
    137c:\school\assign~1.c warning: data definition has no type or storage class

    Not sure what this error means, i scanned the program a few times for missing semicolons, brackets. Im using bloodshed dev c++ ver 4 compiler. on windows xp

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    Oh, and welcome to the boards, thanks for using code tags you get extra points for that.

    Code:
              printf("\n\n Distance (in KM): %10.2f", fDist);
              system("PAUSE");
              system("CLEAR");
            }
          }
    one too many brackets.
    Last edited by jverkoey; 10-08-2004 at 12:01 AM.

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    You have one too many closing } prior to those lines.

    Plus you have a butt load of other warnings and errors to deal with.

  4. #4
    Registered User
    Join Date
    Oct 2004
    Posts
    2
    thanks, it works now...

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > if(cLatD == 'S' || 's')
    Does this work?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 03:40 AM
  3. RicBot
    By John_ in forum C++ Programming
    Replies: 8
    Last Post: 06-13-2006, 06:52 PM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM