Thread: need help

  1. #1
    Registered User
    Join Date
    Feb 2003

    Arrow need help

    trying to see how to enter data into the spa struct for visit_date,
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    int client_info (struct client *D);
    int visit_info ( struct client *D, visitcount);
    struct client 
        char l_name[50];
        char f_name[50];
        char bday[15];
        int height;
        int weight;
        int visits;
        struct spa *V;
    struct spa
        char visit_date[15];  // i want to enter data in this field
        char treat[100];
        double fee;
        char notes[200];
    int main (void)
        int visitcount;
        struct client data[100];
        int i;
        for (i=0;i<5;i++)
            data[i].V[i]= (struct spa *) malloc (5 * sizeof (struct spa));
        printf("Welcome to JP Spa Service's\n\n");
        printf("Choose an option");
        printf("1. Enter New Client");
        printf("2. Search database by lastname");
        printf("3. Search database by date of birth");
        printf("4. Change Client database");
        printf("5. Print record of one client");
        printf("6. Print record of all clients");
        printf("7. Calculate fee of client");
        printf("%s", data[0].l_name);
        visitcount= visitcount;
        free ((void *) V);
    int client_info (struct client *D, int visit_num)
        static int x=0;
        char temp[550];
        int temp1=0;
        int visitcount=0;
        printf("\n Enter First Name:\n");
        strncpy (D[x].f_name, temp, 550-strlen(temp));
        printf("\nEnter Last Name:\n");
        strncpy (D[x].l_name, temp, 550-strlen(temp));
        printf("\nEnter Date of Birth: (exmpl :2, Oct, 1981)");
        strncpy (D[x].bday, temp, 550-strlen(temp));
        printf("\nEnter Weight of Client:\n");
        D[x].weight=atoi (gets(temp));
        printf("\nEnter total number of visits:\n");
        D[x].visits= atoi (gets(temp));
        visit_num = D[x].visits;
        visit_info (D[x]->V[x], visit_num);
        return visit_num;
    int visit_info ( struct client *D, int visit_num)
        int x, y =0;
        if (visit_num <=5)
            x = visit_num;
            x = 5;
        printf("\nEnter Spa visit date (exmpl: 23, Sep, 2002)");
        return 0;

  2. #2
    Join Date
    Nov 2002
    Wow your program gives me tons of warnings and won't run after it compiles. I don't want to go through it all but here are a few things incorrect.

    Use fgets instead. Make sure you check to see if the user left garbage in stdin also. The FAQ has awesome info on grabbing input from the user, you should check it out. It is definitely worth reading.

    int visit_info ( struct client *D, visitcount);
    You need to specify a data type in your second parameter here, also I noticed it differs from the parameter you specified in your definition of the function.

    visitcount= visitcount;
    Like I said I didn't go through all the code, but what is this? I don't understand why you would make that statement.

    You have this after your calls to printf(), I don't see the purpose, I think what you meant is fflush(stdout); Also for future reference fflush(stdin) causes undefined behavior, and it's not the proper way to flush the standard input stream.

    No offense but this seems like code someone has given you to fix, lots of errors hehe. If it isn't sorry and goodluck.

Popular pages Recent additions subscribe to a feed