Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define MINSIZE 1750000
- unsigned int arr_from_file(FILE *file, double *values){
- double input;
- unsigned int i;
- double *new_numbers;
- values = (double *) malloc (MINSIZE*sizeof(double));
- for (i = 1; (!feof(file)); i++) {
- fscanf(file, "%lf\n", &input);
- if (values != NULL){
- if (MINSIZE<i) {
- new_numbers = (double *) realloc (values, i*sizeof(double));
- values = new_numbers;
- }
- values [i-1] = input;
- }
- else {
- printf("ALLOCATION ERROR");
- free(values);
- exit(1);
- }
- }
- return i-1;
- }
- int main(){
- FILE *file = fopen("тут был путь к .txt", "rt");
- unsigned int i, max;
- double values[1];
- max = arr_from_file(file, &values[0]);
- printf("%d\n", max);
- for (i = 0; i<=max; ++i) {
- putchar('p');
- printf("%f\n", values[i]);
- putchar('v');
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement