Advertisement
Niloy007

File Class 02

Jul 22nd, 2020
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.55 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4.     int a = 5;
  5.     int i;
  6.     for (i = 1; i <= a; i++) {  // i = 6
  7.         printf("%d\n", i);
  8.     }
  9.     printf("%d\n", i);
  10. }
  11.  
  12. // int main() {
  13. //  FILE *file;
  14. //  file = fopen("input.txt", "r");
  15.  
  16. //  char name[500];
  17. //  int id;
  18. //  double marks;
  19. //  // EOF = 0 fscanf = 0   0 != 0
  20. //  if(file == NULL) {
  21. //      printf("File does not exist!\n");   // EOF = End of File
  22. //  } else {
  23. //      while(fscanf(file, "%s %d %lf", name, &id, &marks) != EOF) {
  24. //          printf("%s %d %lf\n", name, id, marks);
  25. //      }
  26. //  }
  27. // }
  28.  
  29.  
  30.  
  31.  
  32. // reading data from file
  33. // int main() {
  34.     // FILE *file;
  35.     // file = fopen("input.txt", "r");
  36.     // char name[500];
  37.     // int id;
  38.  
  39.     // if(file == NULL) {
  40.     //  printf("File does not exist!\n");
  41.     // } else {
  42.     //  // taking input from console
  43.     //  // scanf("%s", name);
  44.  
  45.     //  // taking input from file
  46.     //  fscanf(file, "%d", &id);
  47.     //  printf("%d\n", id); // output -> console
  48.  
  49.     //  fprintf(file, "%d\n", id);   // -> file e print korbe
  50.     // }
  51. // }
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. /*
  59.     Creating a new File
  60.     fopen("file path", file_mode);
  61.  
  62.     opening an existing file
  63.     fopen("file path", file_mode);
  64.  
  65.     closing a file            
  66.     fclose(file_pointer);
  67.  
  68.     Reading from and writing information to a file
  69.  
  70.         To write something in a file ->
  71.         fputs(string, file)
  72.         fprintf(file_pointer, formate_specifier, variable_Name)
  73.  
  74.         To read something in a file ->
  75.         fgets(variable, size, file_pointer)
  76.         fscanf(file_pointer, formate_specifier, variable_name) ---> %[^\n]
  77.  
  78. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement