Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- enum {INF = 1000*1000*1000};
- void readOne(FILE *inp, int *to){
- if (fscanf(inp, "%d", to) < 1)
- *to = INF;
- }
- int getMin(int *arr, int count){
- int i, min = 0;
- for (i = 1; i < count; i++)
- if (arr[i] < arr[min])
- min = i;
- return min;
- }
- int main(int argc, char **argv){
- if (argc < 2)
- return 0;
- FILE **inps = (FILE **)malloc((argc - 1) * sizeof(FILE *));
- int *cur = (int *)malloc((argc - 1) * sizeof(int));
- int i, min;
- for (i = 0; i < argc - 1; i++){
- inps[i] = fopen(argv[i + 1], "r");
- readOne(inps[i], &cur[i]);
- }
- while (cur[min = getMin(cur, argc - 1)] != INF){
- printf("%d ", cur[min]);
- readOne(inps[min], &cur[min]);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment