Computer Science, asked by jeevan8701, 1 year ago

write a c program to have the output go two place at once (the screen and to the file also)

Answers

Answered by kvnmurty
5

#include <studio.h>


main()

{

FILE * fp; // line1

char *c = "This is a sample string.\n";

fp = fopen ("myfile" , "w");

fwrite (c, fp); // line 4

printf (c); // line 5

fclose (fp);

}


Another way of having the same character string on the screen as well as in a file is to write the program with just lines 2 and 5. Then compile, execute the program as usual and execute once again with redirection of output to the file "myfile" .



kvnmurty: :)
Similar questions
Science, 7 months ago