Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <cstdlib>
- #include <stdio.h>
- using namespace std;
- int* File1D(const char file[50]);
- int* make1D(int size);
- void secureFile(FILE* f);
- void fel1();
- int main()
- {
- fel1();
- }
- void fel1() {
- int* arr=File1D("be.txt");
- for (int i = 0; i < 5; i++) {
- printf("%d\n", arr[i]);
- }
- }
- int* File1D(const char file[50])
- {
- FILE* f = fopen(file, "rt");
- secureFile(f);
- int counter=0;
- while (fscanf(f,"%d")!=EOF) {
- counter++;
- }
- int* arr = make1D(counter);
- int i = 0;
- while (fscanf(f, "%d",arr[i]) != EOF) {
- i++;
- }
- return arr;
- }
- int* make1D(int size)
- {
- int* arr = (int*)malloc(size * sizeof(int));
- return arr;
- }
- void secureFile(FILE* f)
- {
- if (!f)
- {
- puts("Nem sikerult megnyitni az allomanyt.");
- exit(43);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement