String replacing

I am having trouble with string parsing and replacing. Here is my code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main(){
	char inputData[100];
	ifstream airmar;
	cin.getline(inputData, 100); // you type in the directory or
	airmar.open(inputData);      // if file is in the same directory
	if(!airmar.is_open()){       // then just the file name with ".txt"
		exit(EXIT_FAILURE);
	}
	char data[500000];			// where the weather data will be stored
	airmar >> data;				// put data into char array
	while(airmar.good()){		// while text file is open then 
		cout << data << "\n";
		airmar >> data;
	}
	system("PAUSE");
	return 0;
}

I have the program read from a text file then I want to replace certain bits of string with other pieces of string which will be done in the text file. Here is part of the text file.
$WIMDA,27.2739,I,0.9236,B,28.9,C,,,,,,,,,,,,,,*37
$WIMWD,,,,,,,,*40
$WIMWV,,T,,,V*7C
$WIMWV,291.0,R,0.8,N,A*21
$TIROT,-23.4,A*23
$WIMWV,291.9,R,0.8,N,A*28
$TIROT,-29.3,A*2E
$GPGGA,,,,,,0,,,,,,,,*66
$GPVTG,,,,,,,,,N*30
$GPZDA,,,,*48
$WIMDA,27.2739,I,0.9236,B,28.9,C,,,,,,,,,,,,,,*37
$WIMWD,,,,,,,,*40
$WIMWV,,T,,,V*7C
$WIMWV,288.9,R,0.8,N,A*20
$TIROT,-29.3,A*2E
$WIMWV,291.7,R,0.8,N,A*26
$TIROT,-29.3,A*2E
$GPGGA,,,,,,0,,,,,,,,*66
$GPVTG,,,,,,,,,N*30
$GPZDA,,,,*48
$WIMDA,27.2739,I,0.9236,B,28.9,C,,,,,,,,,,,,,,*37
$WIMWD,,,,,,,,*40
$WIMWV,,T,,,V*7C
$WIMWV,289.8,R,0.6,N,A*2E
$TIROT,-35.1,A*21
$WIMWV,296.0,R,0.6,N,A*28
$TIROT,-29.3,A*2E
$GPGGA,,,,,,0,,,,,,,,*66
$GPVTG,,,,,,,,,N*30
$GPZDA,,,,*48

I would replace parts such as "$WIMWV" with "Wind speed and velocity".
This would be rewritten into the text file.
any suggestions?

Thanks.
Hi,

there is a nice library for parsing GPS data here :
http://arduiniana.org/libraries/tinygps/
This is for arduino but arduino uses C++ (almost)
You can follow this example to create your parse/replace this is a nice one.

Good luck
Topic archived. No new replies allowed.