Page 1 of 1

Problem in file read in c-zOS

PostPosted: Wed Feb 13, 2013 3:35 pm
by anandhakrishna
Guys,

Am trying to open a file and read the content of the file . Here is my code

#include<stdio.h>                                 
#include<stdlib.h>                                 
#include<string.h>                                 
#include<file.h>                                   
#include <"U345175.CPP.SAVE">                     
main()                                             
{                                                 
int c;                                             
FILE *file;                                       
file = fopen("U345175.CPP.SAVE", "rb,type=record");
if (file != NULL)
{                               
                       while ((c = getc(file)) != EOF)               
 putchar(c);                                       
             
    fclose(file);                                 
}                                                 


Am compiling the above prog using the proc EDCQCBG.
Am not getting any error after compilation and also not getting the output content.

Kindly help.
Thanks in advance :)

Code'd, for what is was worth

Re: Problem in file read in c-zOS

PostPosted: Wed Feb 13, 2013 3:43 pm
by enrico-sorichetti
why not sprinkle Your code with a few printf to trace the program flow

at first glance You program fails silently because of an open error

why not put an else condition to tell the world that the open has failed ???

any reason for the funny looking include ?

Re: Problem in file read in c-zOS

PostPosted: Wed Feb 13, 2013 5:22 pm
by anandhakrishna
I Tried by including else portion in the code. It seems that the if condition fails and else part being displayed.

Is the fopen syntax right in this context.

Regards,
AK

Re: Problem in file read in c-zOS

PostPosted: Wed Feb 13, 2013 6:06 pm
by enrico-sorichetti
while in the <&unix> and <windoze> world You are bound to <open> a filename
under zOS id is more appropriate to open using a DDNAME ( read about using the dd: clause )

as
   fopen("dd:<some ddname of Your choice>", "rb,type=record");

Re: Problem in file read in c-zOS

PostPosted: Wed Feb 13, 2013 7:40 pm
by Robert Sample
RTFM. The z/OS C/C++ Run-time Library Reference manual EXPLICITLY tells you that specifying the file as binary (required for record I/O) means you MUST use fread and fwrite with your file. Using getc is not going to work, ever.

And if U345175 is your TSO user id, then you do not have the fopen coded correctly.