Reopen a stream with a different file and mode: how to use freopen : File Open « File « C / ANSI-C






Reopen a stream with a different file and mode: how to use freopen


#include <stdio.h>

int main ()
{
  freopen ("my.txt","w",stdout);
  printf ("This line is redirected to a file.");
  fclose (stdout);
  return 0;
}


           
       








Related examples in the same category

1.Get file name from command line and open the file
2.Open a file and close it
3.Reopen a file
4. Open a file: how to use fopen
5.Open a file for read