首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >它只显示一个酒店预订

它只显示一个酒店预订
EN

Stack Overflow用户
提问于 2019-05-22 09:01:37
回答 2查看 50关注 0票数 1

我正在做酒店预订,所以我试图使用用户插入的iD显示预订,但我无法获取它,程序冻结,没有任何错误或任何东西,我尝试了很多方法,在网上寻找都找不到答案。我试着在if循环中做了一次while,它也不能工作,我找不出问题所在。谢谢。

代码语言:javascript
复制
void display(char *a)
{
    FILE *fp;
    rec = count;
    int choice;
    fp = fopen(a ,"r");
    struct  hotelStruct *temp = (struct hotelStruct *)malloc(sizeof(struct hotelStruct));
    temp->first_name = (char *)malloc(10* sizeof(char));
    temp->last_name = (char *)malloc(15*sizeof(char));
    temp->passport = (char *)malloc(15*sizeof(char));
    temp->nationality = (char *)malloc(30*sizeof(char));
    temp->room = (char *)malloc(10*sizeof(char));
    temp->email = (char *)malloc(30*sizeof(char));
    if (fp == NULL)
        printf("Error!!");
    printf("\nEnter your Reservations iD:\n");
    scanf("%d", &choice);
    fseek(fp, 0, 0);

    while (rec)
    {


        if (choice == temp->id) {
            fread(&temp->id, sizeof(int), 1, fp);
            printf("\niD: %d\n", temp->id);

            fread(temp->first_name, 10, 1, fp);
            printf("First Name: %s\n", temp->first_name);

            fread(temp->last_name, 15, 1, fp);
            printf("Last name: %s\n", temp->last_name);

            fread(temp->passport, 15, 1, fp);
            printf("Passport: %s\n", temp->passport);

            fread(temp->nationality, 30, 1, fp);
            printf("Nationality: %s\n", temp->nationality);

            fread(temp->room, 10, 1, fp);
            printf("Room: %s\n", temp->room);

            fread(&temp->bed, sizeof(int), 1, fp);
            printf("Beds: %d\n", temp->bed);

            fread(temp->email, 30, 1, fp);
            printf("Email: %s\n", temp->email);

            fread(&temp->phone_number, sizeof(int), 1, fp);
            printf("Phone number: %d\n\n\n", temp->phone_number);
        }
        rec--;
    }
    fclose(fp);
    free(temp);
    free(temp->first_name);
    free(temp->last_name);
    free(temp->passport);
    free(temp->room);
    free(temp->email);
    free(temp->nationality);
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56248025

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档