Hi,
I have some data in the form
1 2 3
4 5 6
7 8 9
in a txt file.
How would I go about converting it into a list like:
1
2
3
4
5
6
...etc.
and printing that to another txt file?
Thanks!!
Hi,
I have some data in the form
1 2 3
4 5 6
7 8 9
in a txt file.
How would I go about converting it into a list like:
1
2
3
4
5
6
...etc.
and printing that to another txt file?
Thanks!!
Maybe something like this:
- Read the file to a string
- Replace any consecutive groups of 1 or more whitespace chars with a single '\n'
- Write the string to a file
This may help you with file I/O (don't pay attention that is says C++ Reference):
cstdio (stdio.h) - C++ Reference
Even more simple:
1. Create output file
2. Read a character from input file
3. If it is a <space> right a <newline> character in you output file. Otherwise write the character to your output file as it is
4. Repeat step 2, 3 until EOF
This should just take a few lines of code
That does seem more efficient.
You probably don't want to do this, at all - how's *that* for efficiency?
Nobody (probably) cares how the data is arranged on the drive, unless it's part of a struct or record, which this is not. All they want is to view the data, like:
1
2
3
etc.
So:
Code:fscanf(ptrFile,"%d %d %d", &num1, &num2, &num3); printf("%d\n%d\n%d\n, num1, num2, num3);
Hi,
Read in the data from the original text file and the replace all the character ' ' with '\n'.
Then put it in another file. That's it!
Carle
_______________
Free chat software for you
Why are you just going through threads and repeating everything everyone else has already said?
Quzah.
Hope is the first step on the road to disappointment.
...not to mention threads old enough to be effectively dead...
MTK how would one go about doing your second step
Replace any consecutive groups of 1 or more whitespace chars with a single '\n'
Im having issues with that on my program, but i need it for more than just whitespace, I need more than one whitespace to be combined with commas tabs, etc to return only one '\n'
Quzah.Code:while( (c = fgetc( somefile ) != EOF ) { if( isdigit( c ) ) { ...do whatever for digits... } else if( isspace( c ) ) { while( (c = fgetc( somefile )) != EOF && isspace( c ) ) ; ...do whatever to output your newline... } else { ...do whatever for nonspace nondigit characters... } }
Hope is the first step on the road to disappointment.