Blog Detail

  • c语言中while语句不执行,While 循环不运行,该如何处理

    C/C++ code#include

    struct info{

    char name[20];

    char email[30];

    char tel[20];

    char sex;

    int x,x1,y1,z1,x2,y2,z2;

    int balance;

    char id[11];}client;

    int main()

    {

    FILE *fp1,*fp2;

    printf("Welcome to Sports Booking System registration!\n\n");

    printf("After being a member of our system,\nyou can book the sports facilities at any time you like!!!\nIf you registrate now , you can a bonus of 30 dollars,\nSo come on !!!\n");

    while(1)

    {

    printf("Please inpute the ID you want to use:");

    scanf("%s",&client.id);

    /*printf("%s",client.id);*/

    if((fp1=fopen(client.id,"rb"))!=NULL)//至少这里有一个问题,运算符优先级

    {

    printf("The ID you inpute has already been used! Please choose another ID, sorry for the inconvenient!\n");

    fclose(fp1);

    }

    else

    {

    printf("Please inpute your name:");

    scanf("%s",&client.name);

    /*printf("%s",client.name);*/

    printf("Please inpute your email , so we can send you a email to confirm the booking after you booking the facilites ,\nand we can also remind you before the date you has booked! \nSo make sure that the email is correct!\n");

    printf("Your email address:");

    scanf("%s",&client.email);

    /*printf("%s",client.email);*/

    printf("Please inpute your telephone number , so we can contact you immediately if there is something emergency!\n");

    printf("Your telephone number:");

    scanf("%s",&client.tel);

    /*printf("%s",client.tel);*/

    printf("Please input your sex:");

    fflush(stdin);

    client.sex=getchar();

    client.x=0;client.x1=6;client.y1=0;client.z1=0;client.x2=6;client.y2=0;client.z2=0;

    client.balance=30;

    fp2=fopen(client.id,"wb");

    fwrite(&client,sizeof(struct info),1,fp2);

    fclose(fp2);

    printf("Thank you for complete registration.Now you can log in the booking system to book the facilities . Also you have already 30 dollors in your account.\n");

    break;

    }

    }

    }