Dec 5, 2015 at 7:05am UTC
Hi.
What is wrong with me reading the text file?
1 2 3 4 5 6 7 8 9 10 11 12
int main(){
...........
int fh = _open("g://PA2//10.txt" , fh);
fh=_read(fh,a,70000);
...............
for (int k=0;k<20;++k)
cout << a[k] <<' ' ;
cout<< endl;
.................
return 0;
}
Last edited on Dec 5, 2015 at 7:06am UTC
Dec 5, 2015 at 10:30am UTC
Thanks.But the problem is this:
I need to print my file this way:
1 2 3 4
for (int k=-4;k<100;++k)
cout << a[k] <<' ' ;
cout<< endl;
A problem I have never faced in my whole life!
Last edited on Dec 5, 2015 at 10:38am UTC
Dec 5, 2015 at 10:47am UTC
I could not figure out myself
That worked for an ad-hoc content and not for another content.
Last edited on Dec 5, 2015 at 10:51am UTC
Dec 5, 2015 at 3:31pm UTC
After reading, I'd have strange characters in my file.
Then when I convert them to numbers, I get unexpected results.
Dec 5, 2015 at 3:47pm UTC
Can you post part of the file?
Dec 5, 2015 at 3:52pm UTC
How was a declared?
Are you sure you've actually read the number of characters you're trying to print?
Wouldn't it be better to use the value returned from your _read() call to control your loop?
Dec 5, 2015 at 7:17pm UTC
The file:
3
9
8
4
6
10
2
5
7
1
------------------------------------------------
Def. of a:
char a[700000];
Dec 5, 2015 at 7:29pm UTC
Why are you trying to read a series of numbers as a series characters?
And why are you trying to use the low level function _open() instead of the higher level functions? If you're writing a C function fopen() or in C++ using the file streams.
Dec 5, 2015 at 7:41pm UTC
OK, I was making a stupid mistake in making fh get the value of _read(fh, ...)
Interesting.................I was taught that the RHS of the assignment gets evaluated first.