Advertisement
Guest User

Bug

a guest
Dec 13th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <cstdlib>
  3. #include <stdio.h>
  4.  
  5. using namespace std;
  6.  
  7. int* File1D(const char file[50]);
  8. int* make1D(int size);
  9. void secureFile(FILE* f);
  10. void fel1();
  11.  
  12. int main()
  13. {
  14. fel1();
  15. }
  16.  
  17. void fel1() {
  18. int* arr=File1D("be.txt");
  19. for (int i = 0; i < 5; i++) {
  20. printf("%d\n", arr[i]);
  21. }
  22. }
  23.  
  24. int* File1D(const char file[50])
  25. {
  26. FILE* f = fopen(file, "rt");
  27. secureFile(f);
  28.  
  29. int counter=0;
  30.  
  31. while (fscanf(f,"%d")!=EOF) {
  32. counter++;
  33. }
  34.  
  35. int* arr = make1D(counter);
  36.  
  37. int i = 0;
  38.  
  39. while (fscanf(f, "%d",arr[i]) != EOF) {
  40. i++;
  41. }
  42.  
  43. return arr;
  44. }
  45.  
  46. int* make1D(int size)
  47. {
  48. int* arr = (int*)malloc(size * sizeof(int));
  49. return arr;
  50. }
  51.  
  52. void secureFile(FILE* f)
  53. {
  54. if (!f)
  55. {
  56. puts("Nem sikerult megnyitni az allomanyt.");
  57. exit(43);
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement