Начал 22 Задачу
This commit is contained in:
parent
427a6611df
commit
c3182c8c24
5 changed files with 91 additions and 0 deletions
|
@ -5,6 +5,7 @@
|
|||
int main(void) {
|
||||
double * numbers;
|
||||
FILE * file = getFile();
|
||||
if (file == NULL) return -1;
|
||||
|
||||
numbers = getList(file);
|
||||
if (numbers == NULL) return 1;
|
||||
|
|
0
22Ex/input.txt
Normal file
0
22Ex/input.txt
Normal file
30
22Ex/main.c
Normal file
30
22Ex/main.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include <stdio.h>
|
||||
#include "tools.h"
|
||||
|
||||
int transposition(double * numbers);
|
||||
|
||||
int transposition(double * numbers) {
|
||||
unsigned length = (int)numbers[0];
|
||||
|
||||
|
||||
int last_index = -1;
|
||||
unsigned last_length = 0;
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
double * numbers;
|
||||
FILE * file = getFile();
|
||||
if (file == NULL) return -1;
|
||||
|
||||
numbers = getList(file);
|
||||
if (numbers == NULL) return -1;
|
||||
|
||||
if (transposition(numbers) != 0) return -1;
|
||||
|
||||
for (int i = 1; i < numbers[0]; ++i) printf("%d ", numbers[i]);
|
||||
|
||||
free(numbers);
|
||||
return 0;
|
||||
}
|
50
22Ex/tools.c
Normal file
50
22Ex/tools.c
Normal file
|
@ -0,0 +1,50 @@
|
|||
#include "tools.h"
|
||||
|
||||
FILE * getFile(void)
|
||||
{
|
||||
FILE * file;
|
||||
char filename[50];
|
||||
|
||||
printf("Enter filename: ");
|
||||
if (scanf("%s", filename) == 1)
|
||||
{
|
||||
file = fopen(filename, "r");
|
||||
if (file == NULL) {
|
||||
printf("Error file!\n");
|
||||
return NULL;
|
||||
} else {
|
||||
return file;
|
||||
}
|
||||
} else
|
||||
{
|
||||
printf("Empty name!\n");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
double * getList(FILE * file) {
|
||||
double current;
|
||||
int i, length = 2;
|
||||
double * numbers = NULL;
|
||||
|
||||
if (fscanf(file, "%lf", ¤t) != 1) {
|
||||
printf("File is empty!");
|
||||
return numbers;
|
||||
}
|
||||
|
||||
numbers = (double *)malloc(length * sizeof(double));
|
||||
i = 1;
|
||||
|
||||
do {
|
||||
if (i >= length) {
|
||||
length *= 2;
|
||||
numbers = (double *)realloc(numbers, (length * sizeof(double)));
|
||||
}
|
||||
numbers[i] = current;
|
||||
i++;
|
||||
} while (fscanf(file, "%lf", ¤t) == 1);
|
||||
|
||||
numbers = (double *)realloc(numbers, i * sizeof(double));
|
||||
numbers[0] = i;
|
||||
return numbers;
|
||||
}
|
10
22Ex/tools.h
Normal file
10
22Ex/tools.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef TOOLS
|
||||
#define TOOLS
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
FILE * getFile(void);
|
||||
double * getList(FILE * file);
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue