Problem in file read in c-zOS



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

Problem in file read in c-zOS

Postby anandhakrishna » Wed Feb 13, 2013 3:35 pm

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
anandhakrishna
 
Posts: 6
Joined: Thu Feb 07, 2013 12:40 pm
Location: Chennai
Has thanked: 0 time
Been thanked: 0 time

Re: Problem in file read in c-zOS

 

Re: Problem in file read in c-zOS

Postby enrico-sorichetti » Wed Feb 13, 2013 3:43 pm

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

Re: Problem in file read in c-zOS

Postby anandhakrishna » Wed Feb 13, 2013 5:22 pm

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
anandhakrishna
 
Posts: 6
Joined: Thu Feb 07, 2013 12:40 pm
Location: Chennai
Has thanked: 0 time
Been thanked: 0 time

Re: Problem in file read in c-zOS

Postby enrico-sorichetti » Wed Feb 13, 2013 6:06 pm

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");
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: 2925
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 154 times

Re: Problem in file read in c-zOS

Postby Robert Sample » Wed Feb 13, 2013 7:40 pm

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


Return to C, C++

 


  • Related topics
    Replies
    Views
    Last post