Page 1 of 1

fgets on z/OS?

PostPosted: Mon Mar 07, 2011 3:00 pm
by kjesse
Hi!

I've a question dealing with reading textfiles on z/Os. How can I use fgets with a file that has new lines? I intend to read record-oriented to the next new line sign, but I have problems with this. I am getting the full maximum size (1024). On Windows the first record of my file ends with 156 Bytes. The file was created not on Windows but on MVS and has new lines. Can anyone help?

kjesse

Re: fgets on z/OS?

PostPosted: Mon Mar 07, 2011 3:18 pm
by enrico-sorichetti
before proceeding clarify Your understanding of C I/O architecture
and the difference between stream and record I/O
when using the LF(line feed) concept there is no record mode IO processing

show the file declaration, the open / fgets You are using
and an hex dump of a few records

see also forum-f12/topic4045.html?hilit=fread

for a short discussion about record/stream I/O

Re: fgets on z/OS?

PostPosted: Mon Mar 07, 2011 4:06 pm
by Robert Sample
The file was created not on Windows but on MVS and has new lines.
Terminology is critical in IT, where similar terms may mean very different things. z/OS (MVS) files do not have "new lines" -- they are record-based and there is absolutely no line termination sequence at all (unlike Windows and Unix machines). Further, depending upon the operating system the line termination sequence for a text file may be CR (carriage return), LF (line feed), or CRLF (both) -- and none of these are "new line" characters, which has an entirely different hexadecimal representation (both in ASCII and EBCDIC). So your statement is not true because MVS files don't have "new lines" and Windows text file lines don't end with "new lines" either.

Re: fgets on z/OS?

PostPosted: Thu Mar 10, 2011 8:36 am
by steve-myers
A file created in MVS as a Unix System Services file follows Unix conventions, except the file uses EBCDIC rather than ASCII. If z/OS FTP sends the file to Windoze as a text file, the two FTPs should translate a Unix style end of line to a Windoze style end of line. The original post does not state if a USS file is being sent or a traditional z/OS file is being sent. Linux, of course, is Unix, and the file is already in ASCII.

Re: fgets on z/OS?

PostPosted: Fri Mar 11, 2011 1:52 am
by kjesse
Hi!

Thank you very much for helping. Record-oriented reading with fp = fopen("DD:INPUT","rb,type=record") worked. :D The output was fine. But I have another problem now. How can I get the correct file size when opening with mode "type=record"? ftell/fseek just renders the number of records, but I need the real size of the file in bytes.

Best wishes

kjesse

Re: fgets on z/OS?

PostPosted: Fri Mar 11, 2011 2:05 am
by enrico-sorichetti
You get the file size by multiplying the number of records by the record length
see also
forum-f12/topic4045.html?hilit=fread