Page 1 of 1

Read file problem

PostPosted: Thu Aug 12, 2010 2:34 pm
by Greenhouse
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?

Re: Read file problem

PostPosted: Sun Aug 15, 2010 11:58 am
by Greenhouse
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!

Re: Read file problem

PostPosted: Sun Aug 15, 2010 7:12 pm
by enrico-sorichetti
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 !

Re: Read file problem

PostPosted: Mon Aug 16, 2010 11:41 am
by Greenhouse
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

Re: Read file problem

PostPosted: Mon Aug 16, 2010 3:51 pm
by enrico-sorichetti
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

Re: Read file problem

PostPosted: Mon Aug 16, 2010 6:22 pm
by Greenhouse
Thank you.

As I understood C++ fstreams not support record i/o ?

Re: Read file problem

PostPosted: Mon Aug 16, 2010 6:47 pm
by enrico-sorichetti
You must evaluate wether use mixed I/O processing ( C++ and C models )
or do Your own deblocking, it is really very simple !