nmea sentence

This is a discussion on nmea sentence within the C++ Programming forums, part of the General Programming Boards category; Hey people, Im working with NMEA sentences and am having trouble parsing them. The NMEA sentence is delimited by commas. ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    6

    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?

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    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)
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reversing Letters in Words of a Sentence
    By CRSpeedy in forum C Programming
    Replies: 10
    Last Post: 03-31-2009, 07:12 PM
  2. vector<...>::iterators and insert - I'm stumped.
    By Dino in forum C++ Programming
    Replies: 6
    Last Post: 12-25-2007, 06:11 AM
  3. Random Sentence From A File
    By gandil in forum C Programming
    Replies: 3
    Last Post: 01-08-2006, 09:50 AM
  4. mafia game
    By italiano40 in forum Game Programming
    Replies: 7
    Last Post: 11-07-2005, 01:22 AM
  5. Searching for words within a sentence
    By drdroid in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21