Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <stdarg.h>
- int quantity = 0;
- void load_array(long int **array,FILE *output); //To load array from file
- void close_files(int quantity,...);
- int main(int argc, char *argv[])
- {
- FILE *input1 = NULL, *input2 = NULL, *output = NULL; //file's pointers
- long int*array1 = NULL , *array2 = NULL; //variant with the local variables
- int quantity = 3;
- if (!(input1 = fopen(argv[1], "r")))
- {
- printf("Here is the error while opening input file %s!\n", argv[1]);
- exit(1);
- }
- if (!(input2 = fopen(argv[2], "r")))
- {
- printf("Here is the error while opening input file %s!\n", argv[2]);
- exit(2);
- }
- if (!(output = fopen(argv[3], "w")))
- {
- printf("Here is the error while opening output file &s !" , argv[3]);
- exit(3);
- }
- /*load_array(&array1,*input1);
- printf("\n");
- load_array(&array2,*input2);
- printf("\n");*/*
- /*for (int counter = 0 ; counter < quantity; counter++)
- fprintf(output,"%ld ", array1[counter]);*/
- close_files( 0, 0);
- return 0;
- }
- void load_array(long int **array,FILE* input)
- {
- int counter = 0, decimal = 0 , numbers = 0 ;
- char current_symbol, *temporary_buffer = NULL;/* *temporary_pointer = temporary_buffer;*/
- while (!feof(input))
- {
- current_symbol = fgetc(input);
- if ((current_symbol != ' ') && (current_symbol != EOF) && (current_symbol != '\n'))
- {
- temporary_buffer = (char*)realloc(temporary_buffer, ++counter * sizeof(char));
- temporary_buffer[counter-1] = current_symbol;
- }
- if ((current_symbol == ' ') || (current_symbol == '\n'))
- {
- numbers++;//To estimate how much numbers we have
- decimal = 0;
- int digits = 0;
- for (int coun = 0 ; coun<counter;coun++) //To use gorner to convert string into integer
- {
- decimal = decimal * 10 + (isdigit(temporary_buffer[coun]) ? (temporary_buffer[coun] - '0') : (temporary_buffer[coun] - 'A' + 10));
- digits++;
- }
- //???
- *array = (long int*)malloc( 100* sizeof(long int));
- //array[numbers-1] = (long int*)realloc(array[numbers - 1], sizeof(long int));
- **array++ = decimal;
- //*array++;
- free(temporary_buffer);
- temporary_buffer = NULL;
- counter = 0;
- }
- }
- quantity = numbers;
- /*for (int counter = 0; counter < numbers; counter++)
- printf("%ld ", **array);*/
- return;
- }
- void close_files(int quantity,...)
- {
- int counter = 0;
- va_list argument_pointer;
- va_start(argument_pointer, quantity);
- while (counter++ < quantity)
- {
- fclose(*(va_arg(argument_pointer, FILE**)));
- }
- va_end(argument_pointer);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement