Advertisement
anik1612

File write in c

Feb 19th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. //author: Anik Sarker
  4. //date: Feb 20, 2020
  5.  
  6. int main()
  7. {
  8.  
  9.     FILE *file; //file pointer
  10.  
  11.     int num;
  12.  
  13.     //file directory, and file mode
  14.     file = fopen("multiplication table.txt","w");
  15.  
  16.     if(file == NULL) //check file exist or not
  17.     {
  18.         printf("File doesn't exist");
  19.     }
  20.  
  21.     else
  22.     {
  23.         printf("File is opened\n");
  24.  
  25.         printf("Enter number who's multiplication table you want: ");
  26.         scanf("%d", &num);
  27.         fprintf(file, " Multiplaction table of %d   \n", num);
  28.         fprintf(file, " -------------------------   \n", num);
  29.         for(int i=1; i<=10; i++){
  30.             fprintf(file,"       %d * %d = %d\n",num, i, num * i);
  31.         }
  32.  
  33.         printf("File is written successfully\n");
  34.  
  35.         //file close
  36.         fclose(file);
  37.     }
  38.  
  39.     getch();
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement