-
nmea sentence
Hey people,
Im working with NMEA sentences and am having trouble parsing them. The NMEA sentence is delimited by commas. So, I have to parse this line and store the data inbetween the commas.
i.e. ,temp,temp1,temp2,,
The problem is I am using a program called wiz-c to do this and it does not have methods normally made available in C++.
So I have came up with this bit of code
Code:
skipComma(1); // skips the first comma
ch=WaitRx(); // reads data into a temp ch variable
if(ch!=',') // if ch does not equal comma then
{
data=ch; // Store ch in variable called data
}
else
{
data='' // If ch does equal comma then set data to nothing
}
I have to do this 10-15 times and record the data in each field.
This doesnt seem to work, anyone got any ideas?
-
You only store a single character, store an entire string instead. Read characters until a comma is found, then store the entire string you got so far and start over. Repeat until EOF (end of file) is found.
Code:
list all_words = EmptyList();
string current_word = "";
while(!Eof())
{
char current_char = GetChar();
if(current_char == ',')
{
all_words.add(current_word);
current_word = "";
}
else
{
current_word += current_char;
}
}
(the functions above are pseudo-like, use whatever functions exists on your system)