0

Hi guys,

I have a txt file in which each line contains information in following format:

VELOCITY<100.0>
LAT_1<N 00 00.0000>
LON_1<E 000 00.0000>
SIMULATE<false>

I would like to write a C or C++ programm to select only the values of the words I need. I need those values to do further calculations.
In this example I would need 100.0 and 00 00.0000 and 000 00.0000

I'm just beginning to programm in C, so could anybody help me writing this code?

Thx,

Kevin

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Kevin_160
0

read each line of the file, then search the line for each of the key words you want to use. For example

std::string line;

if( line.find("VELOCITY") != string::npos)
{
   // blablas
}
else if( line.find("LAT_1") != string::npos)
{
  // blabla
}
// etc. etc.

>>I'm just beginning to programm in C,
This is the c++ forum, not c forum :)

Edited by Ancient Dragon: n/a

0

Thanks for the help.
I've started as from today with the programming, since I need it for a project this semester and for my thesis and I think I'll be picking up C++.
I've succeeded in reading the file.
The code you wrote, is it looking for everything wich differs from char's? How do I store the value?
I've started with C++ for dummies, but stream I/O is chapter 24, so excuse me if my questions are basic.
Do you advise a better book or website?

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int VEL_X;
int LAT;
int LON;
int main ()
{
  string line;
  ifstream text("NK.txt");
  if (text.is_open())
  {
    while (! text.eof() )
    {
      getline (text,line);
      cout << line << endl;
    }
    text.close();
  }

  else cout << "Unable to open file"; 
  
  std::string linee;
  
  if( linee.find("VELOCITY") != string::npos)
      {
          
      }

  else if( linee.find("LAT_1") != string::npos)
      {

            // blabla

      }


  system("pause");
  return 0;
}

thx,

Kevin

Edited by WaltP: Added CODE tags -- with all the help about them, how could you miss using them????

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.