Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main(void)
- {
- FILE *f;
- int *a, *b;
- int i, n, m;
- if((f = fopen("input.txt", "r"))==NULL)
- {
- printf("Open file error!\n");
- return 1;
- }
- if(fscanf(f, "%d", &n)<=0)// Считываю кол-во элементов в 1ом массиве
- {
- printf("Input from file error!\n");
- return 2;
- }
- a = (int*)malloc(n*sizeof(int));
- for(i = 0; i<n; i++)
- {
- if(fscanf(f, "%d", &a[i])<=0)
- {
- printf("Input from file error!\n");
- free(a);
- return 2;
- }
- }
- if(fscanf(f, "%d", &m)<=0)// Считываю кол-во элементов в 2ом массиве
- {
- printf("Input from file error!\n");
- free(a);
- return 2;
- }
- b = (int*)malloc(m*sizeof(int));
- for(i = 0; i<m; i++)
- {
- if(fscanf(f, "%d", &b[i])<=0)
- {
- printf("Input from file error!\n");
- free(a);
- free(b);
- return 2;
- }
- }
- // Массивы считаны
- free(a);
- free(b);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement