Hi, I'm new to this fourm I want to ask if anyone can help.I have a program for a GPS receiver it is in C ,for testing I assume the string of GPS message, it doesn't have any errors but it didn't run I don't know why. I used the ICC11 compiler.

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


#define MAXSIZE 100


// char read from COM port
char  charRead[13];


charRead[0]='$GPRMC';
charRead[1]='123519';
charRead[2]='A';
charRead[3]='4807.038';
charRead[4]='N';
charRead[5]='01131.000';
charRead[6]='E';
charRead[7]='022.4';
charRead[8]='084.4';
charRead[9]='230394';
charRead[10]='003.1';
charRead[11]='W*6A';
charRead[12]='\0';



//unsigned char  SC0DR;


//  Buffer collects chars read from GPS
unsigned char  stringRead[MAXSIZE];


//  Set an array for each attribute
unsigned char  tempString[MAXSIZE];
unsigned char  timeString[12];
unsigned char  latitudeString[11];
unsigned char  latitudeCardinalString[3];
unsigned char  longitudeString[12];
unsigned char  longitudeCardinalString[3];
unsigned char  speedString[11];
unsigned char  dateString[11];


//  Declare pointer
unsigned char  *pChar;


//  Coordinated Universal Time(GMT) & Eastern Standard time
unsigned  long utcTime, estTime;
unsigned  long utcHour, estHour;
unsigned  long utcMinutes, estMinutes;
unsigned  long utcSeconds, estSeconds;
unsigned  long date;
unsigned  long day,month,year;


//  Sets the last comma position
unsigned  char lastCommaPosition;


//  Sets the Latitude & Longitude
float        latitude;
int      latDegrees;
float        latMinutes;


float   longitude;
int     longDegrees;
float       longMinutes;
float   speed;



//  dummy variable
unsigned int   j, k;


//  Number of chars read per GPS message string
unsigned int     i;
//  Number of GPS strings read
unsigned int     numLinesRead;


//  initializing the serial ports SCI0 & SCI1


//  Enter a loop for reading char from serial port(Data Reg.)


//do {


void main(void){


// checks if GPS messages start with $  char
#if charRead=='$'
i = 0;
numLinesRead++;
stringRead = charRead;  /*  include each char read to the array


/* By this point, a complete GPS string has been read so save it         /* Append the null terminator to the string read */
stringRead[i+1] = '\0';


/* Analyze string that we collected */
j = 0;
pChar = stringRead; /*     put a pointer for the stringRead   array*/
while(*(pChar+j) != COMMA) {       /* COMMA  0x2C */


tempString[j] = *(pChar+j); /*store the string before the comma */
j++;
}


tempString[j] = '\0';   /* append the null to the end


/* Check if string we collected is the $GPRMC message */
#if tempString[3] == 'R' && tempString[4] == 'M' && tempString[5] == 'C'


/* Found GPRMC string. It has 11 commas total. Its NMEA sentence structure is:


$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A


Where:
RMC          Recommended Minimum sentence C
123519       Fix taken at 12:35:19 UTC
A            Status A=active or V=Void.
4807.038,N   Latitude 48 deg 07.038' N
01131.000,E  Longitude 11 deg 31.000' E
022.4        Speed over the ground in knots
084.4        Track angle in degrees True
230394       Date - 23rd of March 1994
003.1,W      Magnetic Variation
*6A          The checksum data, always begins with *
*/


pChar = stringRead;  /* pointer to the String read


/* Get UTC time */


j = 7;  /* start of time field */
k = 0;


while(*(pChar+j) != COMMA) { //loop until a comma is found
timeString[k] = *(pChar+j);   //save in the time string
j++;
k++;
}


lastCommaPosition = j; //  save the position of the last comma
timeString[k] = '\0'; // append the null to the end


sscanf(timeString, "%ld", &utcTime); //save the string to the variable


utcHour = (utcTime/10000); //extract Hours from long
utcMinutes = (utcTime - (utcHour*10000))/100;  //extract minutes from long
utcSeconds = utcTime - (utcHour*10000) -    (utcMinutes*100);                     /* extract seconds from long */


#if(utcHour >= 0 && utcHour <= 20)
estHour = utcHour + 3;
#endif


#elseif estHour = utcHour - 21;
estMinutes = utcMinutes;
estSeconds = utcSeconds;
#endelseif



/* Get lattitude: ddmm.mmmm */


pChar = stringRead;
j = lastCommaPosition + 1; //start from the next comma
k = 0;
while(*(pChar+j) != COMMA) {
latitudeString[k] = *(pChar+j); //save in the latitude string
j++;
k++;
}
lastCommaPosition = j;
latitudeString[k] = '\0';


sscanf(latitudeString, "%f", &latitude);
latDegrees = (int)(latitude/100);
latMinutes = (float)(latitude - latDegrees*100);


/* Get lattitude Cardinal direction */


pChar = stringRead;
j = lastCommaPosition + 1;
k = 0;


while(*(pChar+j) != COMMA) {
latitudeCardinalString[k] = *(pChar+j);
j++;
k++;
}
lastCommaPosition = j;
latitudeCardinalString[k] = '\0';



/* Get longitude: dddmm.mmmm */


pChar = stringRead;
j = lastCommaPosition + 1;
k = 0;


while(*(pChar+j) != COMMA) {
longitudeString[k] = *(pChar+j);
j++;
k++;
}


lastCommaPosition = j;
longitudeString[k] = '\0';


sscanf(longitudeString, "%f", &longitude);
longDegrees = (int)(longitude/100);
longMinutes = (float)(longitude - longDegrees*100);


/* Get Speed in Knots */
pChar = stringRead;


j = lastCommaPosition + 1;
k = 0;


while(*(pChar+j) != COMMA) {
speedString[k] = *(pChar+j);
j++;
k++;
}


lastCommaPosition = j;
speedString[k] = '\0';


sscanf(speedString, "%f", &speed);
speed = speed * 1.852;


/* Get date  */


pChar = stringRead;


j = lastCommaPosition + 2; // skip the Track angle
k = 0;


while(*(pChar+j) != COMMA) {
dateString[k] = *(pChar+j);
j++;
k++;
}


lastCommaPosition = j;
dateString[k] = '\0';


sscanf(dateString, "%ld", &date);


day = (date/10000); //extract day from long
month = (date - (day*10000))/100;  // extract month from long
year = date - (day*10000) - (month*100); // extract year from long



//else not a GPRMC sentence
#endif


// otherwise not a $ character... so loop back until one arrives
#endif
//  } while(1);
printf("The Result ....\n");
printf("%02ld:%02ld:%02ld UTC = %02ld:%02ld:%02ld EST", utcHour, utcMinutes, utcSeconds, estHour, estMinutes, estSeconds);
printf("\t%02d DEG\t%2.4f MIN", latDegrees, latMinutes);
printf(" %s", latitudeCardinalString);
printf("\t%03d DEG\t%2.4f MIN", longDegrees, longMinutes);


} /* end of main */
Member Avatar for iamthwee

[off topic]
@ cscgal that little thing you did to correct the problem of ppl using code tags isn't working. You know what I mean ;)

Sorry to the OP.

No, what do u mean exactly!!!!!!!!!!!!!

Member Avatar for iamthwee

No, what do u mean exactly!!!!!!!!!!!!!

Sorry, that message wasn't meant for you, but the host of this website.

Anyway when you compose your post you need to use code tags to preserve formatting.

Just highlight your code and press the '#' symbol above. You can also preview what your post will look like before sumbitting it a la

Insert coda here

That way it makes it easier for people to debug your code and help you out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.