There is a structure - discipliny
with a variety of fields and an array of disciplina[n]
. Dynamically allocating memory in this form
disciplina = (discipliny*)malloc(sizeof(*disciplina))*n;
It is necessary that when reading from the file of new elements the memory for the array is automatically expanded. I tried to write in different variations to write
disciplina = realloc(disciplina, sizeof(*disciplina)*i);
but all the errors are written, help write this function correctly.
Full structure code:
struct discipliny {char nazvanie[20], otchet[6]; int vse_chasy; }
Announcement in Maine:
discipliny *disciplina; disciplina = (discipliny*)malloc(sizeof(disciplina)*n);
File reading function:
while(fscanf(file, "%d\n")==NULL)
{
fscanf(file,"%s", disciplina[i].nazvanie); fscanf(file," %d\n", &(disciplina[i].vse_chasy)); i++; disciplina = realloc(disciplina, sizeof(disciplina)*i); *n=i; } fclose(file);
(discipliny*)malloc(sizeof(disciplina)*n)
, the same errors. - reger