Advertisement
Guest User

Untitled

a guest
May 26th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <locale.h>
  3. #include <conio.h>
  4. #include <stdlib.h>
  5. #define ERROR_OPEN_FILE -3
  6. void read();
  7. int main ()
  8. {
  9. FILE *f;
  10. read();
  11. getch();
  12. return 0;
  13. }
  14. void read ()
  15. {
  16. FILE *f;
  17. char name[] = "array.txt";
  18. int len;
  19. f = fopen(name, "r");
  20.  
  21. if (f == NULL) {
  22. printf("Error opening file");
  23. getch();
  24. }
  25. fscanf(f, "%d", &len);
  26. int array[len];
  27. int i = 0;
  28.  
  29. printf("The inside of file (array x)");
  30. printf("\n%d\n", len);
  31. while (!feof(f))
  32. {
  33. int num;
  34. fscanf(f, "%d", &array[i]);
  35. printf("%d ", array[i]);
  36. i++;
  37. }
  38. fclose(f);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement