Advertisement
rafikamal

File Write

Feb 3rd, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.48 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void fileWrite(char *fileName);
  5.  
  6. int main()
  7. {
  8.     char fileName[] = "output.txt";
  9.    
  10.     fileWrite(fileName);
  11.    
  12.     return 0;
  13.    
  14. }
  15.  
  16. void fileWrite(char *fileName)
  17. {
  18.     FILE *fp;
  19.     int ch;
  20.    
  21.     fp = fopen(fileName, "w");
  22.    
  23.     if(fp == NULL)
  24.     {
  25.         printf("Error opening file.\n");
  26.         exit(1);
  27.     }
  28.    
  29.     while(1)
  30.     {
  31.         ch = getchar();
  32.         if(ch == EOF) break;
  33.         else fputc(ch, fp);
  34.     }
  35.    
  36.     fclose(fp);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement