Issue in transfering data from a dataset



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

Issue in transfering data from a dataset

Postby Dora ji » Fri Jul 26, 2013 11:56 am

Hi all,

I am trying to read a text from a dataset and write to another dataset.I am copying the content from the dataset to a character and from that character to another dataset.But the char datatype is not getting recognised.It shows an error i cant able to figure out what sort of error it is.Please help me to resolve it.
Hereby i have included the code and error

#include<stdio.h>                                                 
void main()                                                       
//*int main(int argc, char *argv??(??))                           
{                                                                 
FILE *fp1,*fp2;                                                   
//*char a??(10??);                                                 
char a;                                                           
fp1=fopen("DD:FILE","r");                                         
fflush(fp1);                                                       
if(fp1==NULL)                                                     
    {                                                             
    printf("cannot open this file");                               
                                                                   
    }                                                             
else                                                               
    {
     printf("File opened");                                       
    }                                                             
fp2=fopen("DD:FILE2","w+");                                       
if(fp2==NULL)                                                     
    {                                                             
    printf("Not able to open this file");                         
    fclose(fp1);                                                   
                                                                   
    }                                                             
    else                                                           
    {                                                             
    printf("File opened");                                         
   do                                                             
    {                                                             
    a=fgetc(fp1);                                                 
    fputc(fp2,a);                                                 
    }while(a!=EOF);
    fflush(fp2);                     
    printf("File flushed");           
    fclose(fp1);                     
    fclose(fp2);                     
    printf("File closed");           
    printf("Process complete");       
    }                                 
    }


Error i got is:

CCN5256 (S) A parameter of type "int" cannot be initialized with an expression of type "FILE *".

CCN6205 (I) The error occurred while converting to parameter 1 of "fputc(int, FILE *)".

These users thanked the author Dora ji for the post:
ahmadreza (Sun Jul 28, 2013 4:28 pm)
Dora ji
 
Posts: 12
Joined: Sun Jul 07, 2013 11:12 pm
Has thanked: 0 time
Been thanked: 1 time

Re: Issue in transfering data from a dataset

Postby NicC » Fri Jul 26, 2013 3:09 pm

For starters - EOF is an "int" a is a "char". Change a to be an "int" - all characters are "int"s anyway.
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 transfering data from a dataset

Postby NicC » Fri Jul 26, 2013 11:51 pm

Having copied your program to my pc and reformatted it and done other things to it like "puts" instead of "printf" I eventually got to the nub of the problem - the arguments to fputc are the character to be written followed by the file it is to be written to.
This is the version that compiled successfully:
#include <stdio.h>

int main(int argc, char *argv)
{
   FILE *fp1,
        *fp2;

   char a;

   fp1 = fopen("DD:FILE","r");

   if (fp1 == NULL) {
       puts("cannot open file 2");
       return 98;
    }
   else
     puts("File 1 opened");

   fp2 = fopen("DD:FILE2","w+");
   if (fp2 == NULL)
    {
       puts("Not able to open file 2");
       fclose(fp1);
       return 99;
    }
    else
       puts("File opened");

   do
   {

       a = fgetc(fp1);
       fputc(a,fp2);

   } while(a != EOF);

   fflush(fp2);
   puts("File flushed");
   fclose(fp1);
   fclose(fp2);
   puts("File closed");
   puts("Process complete");
   return 0;
}
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


Return to C, C++

 


  • Related topics
    Replies
    Views
    Last post