我在C语言项目中遇到严重问题。我创建了一个函数,可以输入一些关于体育中心条目的数据,但现在我要修改这个函数以便这个函数:
我的困难在于此请求的第2点和第3点。有人可以帮助我,我遇到了严重的麻烦
我发布了我要执行此操作的基本代码:
void add_entry()
Date_entry de;
Entry e;
Entry eTemp;
FILE *fEnt; //file corso
FILE *fInd; //file indice del corso
printf("Number: ");
scanf("%d", &e.number);
printf("Name: ");
scanf("%s", &e.name);
printf("Surname: ");
scanf("%s", &e.surname);
printf("Date (DD/MM/YYYY): ");
scanf("%d/%d/%d", &de.day3, &de.month3, &de.year3);
printf("Entry time(HH:MM): ");
scanf("%s", &e.entry_time);
printf("Exit time(HH:MM): ");
scanf("%s", &e.exit_time);
e.deleted = 0;
int cont = 0;
fEnt = fopen(EntryOpen,"r+b");
fread(&eTemp,sizeof(Entry),1,fEnt);
while(eTemp.deleted != 1)
{
fread(&eTemp,sizeof(Entrance),1,fEnt);
cont++;
}
int posInEntry = cont;
fseek(fEnt,cont * sizeof(Entrance),0);
fwrite(&e,sizeof(Entrance),1,fEnt);
fclose(fEnt);
Index x;
Index xTemp;
strcpy(x.key,e.surname);
x.value = e.number;
fInd = fopen(indexOpen,"r+b");
cont = 0;
fread(&xTemp,sizeof(Index),1,fInd);
while(strcmp(xTemp.key,"EMPTY") != 0)
{
fread(&xTemp,sizeof(Index),1,fInd);
cont++;
}
fseek(fInd,cont * sizeof(Index),0);
fwrite(&x,sizeof(Index),1,fInd);
fclose(fInd);
IndexCode y;
IndexCode yTemp;
y.kye = e.number;
y.value = posInEntry;
fInd = fopen(indexCodeOpen,"r+b");
cont = 0;
fread(&yTemp,sizeof(IndexCode),1,fInd);
while(yTemp.key != -1)
{
fread(&yTemp,sizeof(IndexCode),1,fInd);
cont++;
}
fseek(fInd,cont * sizeof(IndexCode),0);
fwrite(&y,sizeof(IndexCode),1,fInd);
fclose(fInd);
IndexCode ind[max];
fInd = fopen(indexCodeOpen,"rb");
int i;
for(i = 0; i < max; i++)
{
fread(&ind[i],sizeof(IndexCode),1,fInd);
}
fclose(fInd);
OrderIndexCode(ind,max);
fInd = fopen(indexCodeOpen,"wb");
for(i = 0; i < max; i++)
{
fwrite(&ind[i],sizeof(IndexCode),1,fInd);
}
fclose(fInd);
printf("Index Update completed.\n");