Hi, I'm sorry to bother you all with this but i've been searching all day to try and solve this but am no further on.
So basically I have a programme which outputs hundreds of .dat files. All of which are in the form filename###.dat where ### is replaced with numbers from 001 all the way up to 999 but could end any number inbetween. So I need to edit each of these .dat files to that first the text at the beginning has a % in front of it, so it's a comment so I can use it in the next programme and then that the repeated data is deleted. Here's an example of one of the dat files:
Any Text
Any Text
Any Text
1 12.01 45.21 43.76 18.23
2 43.32 19.65 64.12 -75.12
3 54.32 64.54 87.12 -18.76
1 65.65 98.23 13.54 76.12
2 62.76 65.24 76.65 -32.12
3 43.12 34.54 76.23 -62.21
So in the above example the second set of 1,2 and 3 long with all the rest of the data in these rows needs to be deleted and % put in front of the first 3 text lines and then this repeated for all the .dat files. Any help anyone could give me with this would be greatly appreciated!
You need to post some code so that we can help. Otherwise it just looks like you are a lazy student who wants his assignment written for him.
Depending on the requirements the above can be solved in various ways more or less complicated ways involving operating system calls etc but the simplest, portable way to solve it is to use the ifstream class and have a loop 1..999 that tries to open the file and if succeeds, read the file line by line writing each line to a new file. If the line number is 1,2,3 write a leading % in front before writing the rest of the line to the new file.
Thanks for your help it's completed now. Sorry if my original post misled you but I was only looking for the best approach for tackling this problem and not the code written for me. This is not an assignment only a means of preparing results for analysis, which is when the real fun will begin! I'll put the code below just incase anyone else may ever make use of it, basic as it is.
Again many thanks for your help it was greatly appreciated.