gpt4 book ai didi

c - 第一个 fwrite 有效但第二个无效

转载 作者:太空宇宙 更新时间:2023-11-04 05:43:00 25 4
gpt4 key购买 nike

<分区>

我不知道为什么 customer 的第一个 fwrite() 有效,但符号的第二个 fwrite() 无效的消息。我的程序想要检查消息中的客户和符号是否已包含在库 .dat 中。这是我的一段代码:

typedef struct {
char Name[50];
int totalmsg;
int totalword;
} Customer;

typedef struct {
char symbol;
char alphabet[20];
} Ssymbol;

void add_customer () {
boolean found;
int i;

fp = fopen("customer.dat", "wb+");
fread(&Customer_history, sizeof(TabInt), 102, fp);

i = GetLastIdx(Customer_history);
do {
printf ("Please input customer's name: ");scanf("%s",&temp);
if (i == 0) {
i++;
SetName(&Customer_history,i,temp);
SetMsg(&Customer_history,i,i);
SetEff(&Customer_history,i);
printf("Do you still wanna add another customer ?(Y/N)"); scanf("%s",&CC);
}
else {
found = Search_name(Customer_history,temp);
if (found == true) {
printf("The name is already exist \n\n");
}
else {
i++;
SetName(&Customer_history,i,temp);
SetMsg(&Customer_history,i,i);
SetEff(&Customer_history,i);
}
printf("Do you still wanna add another customer ?(Y/N)"); scanf("%s",&CC);
}
} while ((CC == 'y') || (CC =='Y'));
fwrite(&Customer_history, sizeof(Customer), 102, fp);
fclose(fp);
}

void add_symbol() {

char tempc;
char tempalphabet[20];
boolean found;
int i;

fp = fopen("library.dat","wb+");

fread(&list_symbol, sizeof(Ssymbol), 52, fp);

i = GetLastIdx2(list_symbol);

do{
printf("Please input new symbol:");
scanf("%s", &tempc);

printf("Please input the alphabet of the symbol:");
scanf("%s", &tempalfabet);

if (i==0){
i++;
SetSymbol(&list_symbol,i,tempc);
SetAlphabet(&list_symbol,i,tempalphabet);
printf("Do you want to add another symbol? (Y/N)");
scanf("%s",&CC);
}
else{
found = Search_symbol(list_symbol, tempc);
if (found==true){
printf("Symbol is already exist \n\n");
}
else{
i++;
SetSymbol(&list_symbol,i,tempc);
SetAlphabet(&list_symbol,i,tempalphabet);
printf("Do you want to add another symbol? (Y/N)");
scanf("%s",&CC);
}
}
}

while((CC=='y') || (CC=='Y'));

fwrite(&list_symbol, sizeof(Ssymbol),52, fp);
fclose(fp);
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com