fwrite()
最初の, が機能する理由はわかりませんが、メッセージのシンボルのcustomer
2 番目は機能しません。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);
}