Computer Science, asked by sufiyanaziz4, 1 year ago

explain the file input and file input and file output function with example program?

Answers

Answered by kvnmurty
9

#include <stdio.h>


main()

{

FILE * fp1, *fp2;

char *c, str[100], *s=str;

fp1 = fopen ("inputfile" ,"r");

fp2 = fopen ("outputfile" ,"w");

if (fp1 == NULL || fp2 == NULL) {

fprintf (stderr, "error \n");

exit(1);

}

// read write each char

for ( c = fgetc (fp1); c != '\0'; ){

// do processing work on char c

fputc (fp2, c);

c = fgetc(fp1 );

}

// or, do input and output word by word...

// for (fgets (fp1,s); s ; ) {

// fputs (fp2,s);

// fgets (fp1,s);

// }

fclose (fp1) ;

fclose (fp2);

}


kvnmurty: :)
nalinsingh: Thank you so much Sir !! Finally you are back !! I missed you so much..... I hope you have remembered me sir I am Pratham when we used to have Rishi sir community.
nalinsingh: After a long time sir !! Glad to have you sir.
Answered by Aaryan102604
2

#include <stdio.h>

main0

FILE fp1, *fp2;

char *c, str[100], *s=str;

fp1 fopen ("inputfile","r");

fp2 fopen ("outputfile","w");

if (fp1 == NULL || fp2 = NULL)

fprintf (stderr, "error \n");

exit(1);

// read write each char

for (c fgetc (fp1); c !'0';

// do processing work on char c

fputc (fp2, c);

= fgetc(fp1);

// or, do input and output word by

word...

// for (fgets (fp1,s); s ;)

/ fputs (fp2,s);

// fgets (fp1,s)

// }

fclose (fp1);

fclose (fp2);

}

Similar questions