Read file problem



Help for C/C++ for MVS, OS/390 C/C++, z/OS C/C++ and C/C++ Productivity Tools for OS/390

Read file problem

Postby Greenhouse » Thu Aug 12, 2010 2:34 pm

Hi,

I have file to read in record mode.

The problem is that some of file lines have newline character in the middle of them,
and it cause unwanted line break.

How to manage it?
Greenhouse
 
Posts: 25
Joined: Tue Sep 02, 2008 1:53 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Read file problem

Postby Greenhouse » Sun Aug 15, 2010 11:58 am

record format VB.

Maybe there is some option when ctreating fstream that will tell to read each record from start to end and split it when linebrak occurs in it?
Or to use C i/o header instead?

Help!
Greenhouse
 
Posts: 25
Joined: Tue Sep 02, 2008 1:53 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Read file problem

Postby enrico-sorichetti » Sun Aug 15, 2010 7:12 pm

remember, in general C has no knowledge of record mode files

anyway all depends on the C compiler You are using...
does Your compiler support something like ...
f = fopen(<file specification>, "rb,type=record");


if yes then Your life will be easier,
otherwise for VB files You will have to do Your own deblocking

do until eof
read four chars "LLbb" to get the block size
do ...
read four chars "LLbb" to get the record size
read LL chars for the record
<PROCESS THE RECORD>
end inner
end outer

for FB files Your life will be easier
no need to do the unblocking
use FREAD to read every time a chunk of bytes corresponding to the lrecl of Your dataset

obviously in binary mode !
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 3003
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Read file problem

Postby Greenhouse » Mon Aug 16, 2010 11:41 am

enrico-sorichetti wrote:anyway all depends on the C compiler You are using...
does Your compiler support something like ...
f = fopen(<file specification>, "rb,type=record");



Yes, luckily for me, I'am using z/OS V1R10.0 XL C/C++ compliler.

How can I know what buffer size to pass to fread() ?

thx
Greenhouse
 
Posts: 25
Joined: Tue Sep 02, 2008 1:53 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Read file problem

Postby enrico-sorichetti » Mon Aug 16, 2010 3:51 pm

if You have the competence to write C/C++ programs
You should have also the competence to do some manual reading yourself
the manuals will tell all You might want to know abut the issue You are facing

starting from
http://www-03.ibm.com/systems/z/os/zos/ ... index.html
and proceeding to the book section of Your zOS level...

here is the path for the 1.9
http://www-03.ibm.com/systems/z/os/zos/ ... books.html
http://www-03.ibm.com/systems/z/os/zos/ ... lves9.html
http://publibz.boulder.ibm.com/cgi-bin/ ... s/CBCBS180

and the You should be able to proceed by Yourself

here is a pointer to a C/C++ bookshelf
http://publibz.boulder.ibm.com/cgi-bin/ ... s/CBCBS180

here the same to the library reference
http://publibz.boulder.ibm.com/cgi-bin/ ... 0725234036

and here the to the relevant programmers guide page
http://publibz.boulder.ibm.com/cgi-bin/ ... 0428041634
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 3003
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Read file problem

Postby Greenhouse » Mon Aug 16, 2010 6:22 pm

Thank you.

As I understood C++ fstreams not support record i/o ?
Greenhouse
 
Posts: 25
Joined: Tue Sep 02, 2008 1:53 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Read file problem

Postby enrico-sorichetti » Mon Aug 16, 2010 6:47 pm

You must evaluate wether use mixed I/O processing ( C++ and C models )
or do Your own deblocking, it is really very simple !
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 3003
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times


Return to C, C++

 


  • Related topics
    Replies
    Views
    Last post