fgets on z/OS?



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

fgets on z/OS?

Postby kjesse » Mon Mar 07, 2011 3:00 pm

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
kjesse
 
Posts: 13
Joined: Tue Sep 21, 2010 9:26 pm
Has thanked: 0 time
Been thanked: 0 time

Re: fgets on z/OS?

Postby enrico-sorichetti » Mon Mar 07, 2011 3:18 pm

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
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: 3006
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 165 times

Re: fgets on z/OS?

Postby Robert Sample » Mon Mar 07, 2011 4:06 pm

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.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: fgets on z/OS?

Postby steve-myers » Thu Mar 10, 2011 8:36 am

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.
steve-myers
Global moderator
 
Posts: 2105
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 243 times

Re: fgets on z/OS?

Postby kjesse » Fri Mar 11, 2011 1:52 am

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
kjesse
 
Posts: 13
Joined: Tue Sep 21, 2010 9:26 pm
Has thanked: 0 time
Been thanked: 0 time

Re: fgets on z/OS?

Postby enrico-sorichetti » Fri Mar 11, 2011 2:05 am

You get the file size by multiplying the number of records by the record length
see also
forum-f12/topic4045.html?hilit=fread
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: 3006
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 165 times


Return to C, C++