Доброго времени суток!
Очень нужна ваша помощь!
Нужно отредактировать код,который написан на Си. Изначально использовались структуры,но как оказалось проект нужно было сделать без них,по этому нужно как то преобразовать код либо чтобы какая то добрая душа помогла заново его переписать. Буду очень благодарен! Заранее спасибо
(Одну функцию я вырезал,она будет в текстовом файле отдельно прикреплена,там написан целый код)
Код:
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <math.h>
#include <stdbool.h>
#include <string.h>
int v(FILE** fr, int* num, char*** nazov, char*** org, _Bool** deti, int** den, double** cena, double** times) {
double price, time;
char string[32];
int i=0, count = 7;
int cislo = 0;
if ((*fr = fopen("podujatia.txt", "r")) == NULL) {
printf("Neotvoreny subor\n");
}
else {
while ((fgets(string, 32, *fr)), feof(*fr) != EOF) {
cislo++;
}
cislo = (cislo + 1) / count;
rewind(*fr);
*nazov = (char**)malloc(cislo * sizeof(char*));
for (i = 0; i < cislo; i++)
(*nazov)[i] = (char*)malloc(32 * sizeof(char));
*org = (char**)malloc(cislo * sizeof(char*));
for (i = 0; i < cislo; i++)
(*org) = (char*)malloc(32 * sizeof(char));
*deti = (_Bool*)malloc(cislo * sizeof(_Bool));
*cena = (double*)malloc(cislo * sizeof(double));
*den = (int*)malloc(cislo * sizeof(int));
*times = (double*)malloc(cislo * sizeof(double));
cislo = 0;
while ((fgets(string, 32, *fr)), feof(*fr) == 0) {
int c = (cislo + 1) / count;
int * names;
if (cislo%count == 0) {
strcpy(names[c], string);
printf("nazov: %s", (*nazov)[c]);
}
int *organizers;
if (cislo%count == 1) {
strcpy(organizers[c], string);
printf("organizator: %s", (*org)[c]);
}
if (cislo%count == 2) {
if (string[0] == '1') (*deti)[c] = 1;
else (*deti)[c] = 0;
printf("pre deti: %d\n", (*deti)[c]);
}
if (cislo%count == 3) {
price = atof(string);
(*cena)[c] = price;
printf("cena: %.2f\n", (*cena)[c]);
}
if (cislo%count == 4) {
(*den)[c] = atoi(string);
printf("datum: %08d\n", (*den)[c]);
}
if (cislo%count == 5) {
time = atof(string);
(*times)[c] = time;
if (((*times)[c] >= 00.00) && ((*times)[c] <= 23.59))
printf("cas: %.2f\n\n", (*times)[c]);
else
printf("Nepravidelne uvedeny cas\n\n");
}
cislo++;
memset(string, 0, 32);
}
rewind(*fr);
cislo= (cislo + 1) / count;
*num = cislo;
return 1;
}
*num = cislo;
return 0;
}
int *podujatie_for_year, *arr;
void program_c() {
FILE* file = fopen("podujatie.txt", "r");
podujatie_for_year *arr = (podujatie_for_year*)malloc(N*sizeof(podujatie_for_year));
char str[255];
while (fgets(str, 255, file)) {
fgets(str, 255, file);
fgets(str, 255, file);
fgets(str, 255, file);
fgets(str, 255, file);
int year;
bool hasy = false;
sscanf(str, "%8d", &year);
year %= 10000;
for (int i = 0; i < N; i++) {
if (arr[i].year == year) {
hasy = true;
arr[i].count++;
}
}
if (!hasy) {
arr[count].year = year;
arr[count].count = 1;
count++;
}
fgets(str, 255, file);
fgets(str, 255, file);
}
int nyear = 0;
int ncount = 0;
for (int i = 0; i < N; i++) {
if (arr[i].count > ncount) {
ncount = arr[i].count;
nyear = arr[i].year;
}
}
if (ncount > 0)
printf("\nmax count of podjatie = %d in %d year\n", ncount, nyear);
free(arr);
fclose(file);
}
int main(void)
{
while (true) {
char c;
printf(">> ");
scanf("%c", &c);
switch (c) {
case 'v': {
program_v();
break;
}
case 'c': {
program_c();
break;
}
case 's': {
program_s();
break;
}
case 'e': {
program_e();
break;
}
case 'r': {
program_r();
break;
}
case 'h': {
program_h();
break;
}
case 'k': {
printf("\execution done");
return 0;
break;
}
default: {
}
}
}
return system("PAUSE");
}