Need help for a treatement of file

I have to do a programm in C on codeblocks. And I don't find algorithm which can execute what I want:
So I explain,

I must do a treatement of file, I have to read a file and create another file with some informations of the file read.

example information in the file to read:

A 16 18 A 15 13 A 22 17 A...

and I have to do a program that allow associate all numbers which not associate, for example:

A 16 18 (is a combinaison), A 15 13 (is another combinaison),...

and in the new file, I must have:

16 15
16 13
16 22
16 17

18 15
18 13
18 22
18 17

15 22
15 13
.
.
.

I must I have this new file type, but I don't know how to do, If someone can help me , please.



Last edited on
closed account (o3hC5Di1)
Hi there,

I can't tell you exactly how to do this, but here's what I'll think you'll need to do the job:

The letters are actually a separator for the numbers, so if you can "scan" the string character by character, you know that as long as you don't find a letter the current character should be on the same line as the previous. In pseudo code:

filestream f;
temp string tmp;
read f character by character;
    if character != A then add character to tmp
    else add '\n' to tmp (for linebreak)


Hope that makes sense and will get you started.
There may be more effective ways to do this, but as it appears that your first file contains just a string (no seperate lines) I'm guessing the above is the way to go.

Another route may be to load the string and loop over a first position search of 'A', then using substring to fetch the data and strip it from the loaded string.

All the best,
NwN
Thank you , NwN !!I wil try it!
Topic archived. No new replies allowed.