帮忙看下下面这个代码问题出在哪
程序代码:
#include<stdio.h> #include<direct.h> #include<string.h> #include<stdlib.h> #define TYPE1 "T123" #define TYPE2 "T456" #define MAX_T123 40 #define MAX_T456 90 #define LEN_train sizeof(struct train) #define LEN_char sizeof(char) #define TRUE 1 #define FALSE 0 struct train { char type[5]; char ID[6]; int price; char date[11]; char s_station[20]; char t_station[20]; int num_passenger; int MAX_passenger; char b_seat[91]; }; struct passenger { char name[20]; char ID[6]; char payment[5]; char re_date[5]; char seat[4]; int num_ticket; }; short strequal(char *str1, char* str2) { int i=0; if (strlen(str1)!=strlen(str2)) return 0; for (i;*(str1+i)!='\0';i++) { if (*(str1+i)!=*(str2+i)) return 0; } return 1; } void re_ID() { short b_test=FALSE; FILE *p1; FILE *p2; int num_ticket; int i; struct train *pt=NULL; struct passenger *pp=NULL; printf("\nPlease enter the train ID:\n"); fflush(stdin); scanf("%s",&pp->ID); printf("Please enter the reservation date:\n"); fflush(stdin); scanf("%s",&pp->re_date); printf("Please enter the number of tickets you want"); fflush(stdin); scanf("%d",&num_ticket); p1=fopen("data_train.dat","wb+"); p2=fopen("data_passenger.dat","wb+"); if((p1=fopen("data_train.dat","rb+"))&&(p2=fopen("data_passenger.dat","rb+"))==NULL) { printf("Fail to load the database,tap to exit..."); getchar(); exit(1); } while(!feof(p1)&&!feof(p2)) { pt=(struct train*)malloc(LEN_train); fread(pt,sizeof(struct train),1,p1); if((strequal(pt->ID,pp->ID)==1)&&((num_ticket < (pt->MAX_passenger - pt->num_passenger))==1)) { b_test=TRUE; pp->num_ticket=num_ticket; pt->num_passenger+=num_ticket; for (i=1;i<pt->num_passenger;i++) { if(pt->b_seat[i]=0) { pt->b_seat[i]=1; break; } else { break; } } } fclose(p1); fclose(p2); if(b_test==FALSE) { printf("\n Train not found, tap to retry......"); getchar(); search_ID(); } else { printf("\n Tap to continue......"); getchar(); } } }