Page 1 of 1

Issue in transfering data from a dataset

PostPosted: Fri Jul 26, 2013 11:56 am
by Dora ji
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 *)".

Re: Issue in transfering data from a dataset

PostPosted: Fri Jul 26, 2013 3:09 pm
by NicC
For starters - EOF is an "int" a is a "char". Change a to be an "int" - all characters are "int"s anyway.

Re: Issue in transfering data from a dataset

PostPosted: Fri Jul 26, 2013 11:51 pm
by NicC
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;
}