Niloy007

File (C)

Nov 25th, 2020
482
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2.  
  3. /*
  4.     Function
  5.         -> Build in function
  6.         -> User define function
  7. */
  8.  
  9.  
  10. int main() {
  11.     FILE *file;
  12.     file = fopen("output.txt", "r");
  13.     char arr[50];
  14.  
  15.     if(file == NULL) {
  16.         printf("File does not exist\n");
  17.     } else {
  18.         while(fscanf(file, "%s", arr) != EOF) {
  19.             printf("%s ", arr);
  20.         }
  21.         printf("\n");
  22.     }
  23. }
  24.  
  25.  
  26.  
  27.  
  28. // int main() {
  29. //  FILE *file;
  30. //  file = fopen("output.txt", "w");
  31.  
  32. //  char arr[50];
  33. //  gets(arr);  // Console
  34.  
  35. //     if(file == NULL) {
  36. //      printf("File does not exist\n");
  37. //  } else {
  38. //      // printf("%s\n", arr);    // Console
  39. //      // fputs(arr, file);       // File
  40. //      fprintf(file, "%s", arr);
  41. //      fclose(file);   // Closing the file
  42. //  }
  43. // }
  44.  
  45. /*
  46.     Creating a new File
  47.     fopen("file path", file_mode);
  48.  
  49.     opening an existing file
  50.     fopen("file path", file_mode);
  51.  
  52.     closing a file            
  53.     fclose(file_pointer);
  54.  
  55.     Reading from and writing information to a file
  56.  
  57.         To write something in a file ->
  58.         fputs(string, file)
  59.         fprintf(file_pointer, formate_specifier, variable_Name)
  60.  
  61.         To read something in a file ->
  62.         EOF = End of File
  63.         fgets(variable, size, file_pointer)
  64.         fscanf(file_pointer, formate_specifier, variable_name) ---> %[^\n]
  65.  
  66. */
  67.  
  68.  
  69. /* Projects
  70. -----------
  71.  
  72. ---> Structure
  73.     --> insertion
  74.     --> delete (optinal)
  75.     --> update
  76.     --> query/search
  77. ---> File   (optional) -> mark thakbe
  78.  
  79. */
  80.  
  81.  
RAW Paste Data