Member Avatar for Kevin_160

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

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 :)

Member Avatar for Kevin_160

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

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.