Issue in processing a file



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

Issue in processing a file

Postby Dora ji » Wed Aug 07, 2013 2:30 pm

Hi all,

Actually i am trying to write and then update the file using seek,I am facing issue there.I am getting maxcc = 4 but nothing is written inside the dataset.In spool i am getting all the printf statements.Please look through my code and let me know the changes.

Thanks in advance!!
#include <stdio.h>                                       
int main(void)                                           
{                                                         
   FILE *fp;                                             
   printf("Process file open\n");                         
   fp = fopen("DD;FILE3","w+");                           
   printf("File opened\n");                                                     
   fputs(fp,"This is C program in Mainframe");               
   printf("Data inserted\n");                             
   fseek( fp, 7, SEEK_SET );                             
   printf("Seek performed\n");                                             
   fputs(fp,"C Programming Langauge");                   
   printf("Data transformed\n");
   fflush(fp);                   
   fclose(fp);                   
   printf("File Closed\n");     
   return(0);                   
}       
Dora ji
 
Posts: 12
Joined: Sun Jul 07, 2013 11:12 pm
Has thanked: 0 time
Been thanked: 1 time

Re: Issue in processing a file

Postby steve-myers » Wed Aug 07, 2013 3:05 pm

I rarely do mainframe C programming, but I see some secondary issues that may not be directly related to your fundamental problem.

I think the file specification in your fopen function call has a problem. I think - but I'm not 100% certain - that it should be DD:FILE3, not DD;FILE3. In other words I think your semi-colon (;) should be a colon (:).

I've never done fseek on the mainframe, and only rarely (as in once, I think, and that was 10 or 20 years ago) on a toy machine, but I'm not comfortable combining fseek and an fopen specification of w+, which, if I remember toy machine C correctly, is to extend a file.
steve-myers
Global moderator
 
Posts: 2105
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 243 times

Re: Issue in processing a file

Postby NicC » Wed Aug 07, 2013 3:19 pm

You have not actually checked that the file was opened by seeing if fp == NULL. Also, you have not checked that fputs() actually wrote to the file if it is open. also, and you had this same error before, the parameters to fputs() are the other way around. Think of it like this: if you are getting (fgets() ) a book you go to the shelf first and get the book (fgets(file, string)) when you are putting (fputs() ) a book back on the shelf you get the book first and go to the shelf (fputs(string,file) ).
It almost looks as though you are getting odd bits and pieces and putting them in a program without reading about them and how they work and should be used. Read the stuff on file i/o before posting, please.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: Issue in processing a file

Postby steve-myers » Wed Aug 07, 2013 4:06 pm

I, too, thought about testing if the file was open, something I'm pretty religious about.

I didn't notice the fputs issues NicC noticed, probably because I make the same mistake myself all too often. The compiler should notice that, anyway, so the program would never get to execution.
steve-myers
Global moderator
 
Posts: 2105
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 243 times

Re: Issue in processing a file

Postby NicC » Wed Aug 07, 2013 4:50 pm

Further, you have basically ignored my response to an earlier query for another program when writing this program.
what is giving you a return code of 4 - the compiler or your execution step. If the compiler step, did the execution step actually run. Are you using a xxxxCLG procedure? I suggest you show us your JESMSGLG, JESJCL and JESYSMSG from your job.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: Issue in processing a file

Postby selinanell » Wed Mar 04, 2015 1:11 pm

JNI is not specific to z/OS, it is standarised and will be available everywhere Java is.

The thing that is specific to EBCDIC based OS's like z/OS is that you have to make the calls to Java using ASCII strings, so for instance use #pragma convert or iconv(), depending on your needs. Other than that, it's JNI as usual.
http://www.solitairewithbuddies.com/
selinanell
 
Posts: 1
Joined: Wed Mar 04, 2015 12:54 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Issue in processing a file

Postby enrico-sorichetti » Wed Mar 04, 2015 2:07 pm

JNI is not specific to z/OS, it is standarised and will be available everywhere Java is.

looks like You replied to the wrong topic

aparte replying to a 2 years old topic, no mention of JAVA, just good old plain C
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++

 


  • Related topics
    Replies
    Views
    Last post