Like Tree2Likes

Help with understanding a given warning

This is a discussion on Help with understanding a given warning within the C Programming forums, part of the General Programming Boards category; Hello All; I have a program that is giving warnings when compiled but I do not understand why. Here is ...

  1. #1
    Registered User
    Join Date
    Jul 2014
    Posts
    34

    Help with understanding a given warning

    Hello All;
    I have a program that is giving warnings when compiled but I do not understand why. Here is the code:

    Code:
    /* Leslie Bauert
       CSE1311 HW 8
       Aug. 11, 2014
     */
    
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    
    struct Members
    {
        char fName[20];
        char lName[20];
        char Email[30];
        char id[20];
        char pass[20];
        char SSN[15];
        char gender;
        double GPA;
        int age;
    
    
    };
    
    
    void Up_Date_Info(struct Members mem[20],int i);
    void View_Info (struct Members mem[20], int i);
    void display();
    
    
    int main()
    {
        int i;
        struct Members mem[20];
        for(i = 0; i < 20; i++)
            {
                strcpy(mem[i].id, " ");
                strcpy(mem[i].pass, " ");
                strcpy(mem[i].Email, "             ");
                strcpy(mem[i].fName, " ");
                strcpy(mem[i].lName, " ");
                strcpy(mem[i].SSN, " ");
                //char gender = '\0';
            }
        char choice;
        char temp[20];
        char temppass[20] = "";
        i = 0;
    
    
         printf("Start Program\n");
         printf("1. Log in\n");
         printf("2. Sign up\n");
         printf("3. Exit\n");
    
    
        do
        {
    
    
            printf("What do you want to do: ");
            scanf("%s", &choice);
            printf("\n");
    
    
            switch (choice)
            {
                case '1':
                    printf("Please enter your id: ");
                    strcpy(temp, "");
                    scanf("%s", temp);
    
    
                    printf("Please enter your password: ");
                    strcpy(temppass, "");
                    scanf("%s", temppass);
                    getchar();
    
    
                    for (i = 0; i < 20; i++)
                    {
                        if (strcmp(temp, mem[i].id) != 0 || strcmp(temppass, mem[i].pass) != 0)
                        {
                            while ((strcmp(temp, mem[i].id) != 0 || strcmp(temppass, mem[i].pass) != 0))
                            {
                                if (strcmp(temp, mem[i].id) != 0)
                            {
                                printf("Please re-enter your id: ");
                                strcpy(temp, "");
                                scanf("%s", temp);
                            }
                            if (strcmp(temppass, mem[i].pass) != 0)
                            {
                                printf("Please re-enter your password: ");
                                strcpy(temppass, "");
                                scanf("%s", temppass);
                                getchar();
                            }
                            }
    
    
                            printf("\n");
                        }
    
    
                        if (strcmp(temp, mem[i].id) == 0 && strcmp(temppass, mem[i].pass) == 0)
                        {
                            printf("Hello %s!!!\n\n", mem[i].id);
                            do
                            {
                                printf("1. View User Account\n");
                                printf("2. Update User Account\n");
                                printf("3. Log out\n\n");
                                printf("What do you want to do?");
                                choice = '\0';
                                scanf("%c", &choice);
                                getchar();
                            switch (choice)
                            {
                            case '1':
                                printf("User id is: %s\n", mem[i].id);
                                printf("User password is: %s\n", mem[i].pass);
                                printf("Your first name is %s\n", mem[i].fName);
                                printf("Your last name is %s\n", mem[i].lName);
                                printf("Your Email is %s\n", mem[i].Email);
                                printf("Your GPA is %.1f\n", mem[i].GPA);
                                printf("Your gender is %s\n", mem[i].gender);
                                printf("Your age is %d\n", mem[i].age);
                                printf("Your SSN is %s\n", mem[i].SSN);
                                printf("\n");
                                break;
    
    
                            case '2':
                                Up_Date_Info(mem, i);
                                getchar();
                                break;
    
    
                            case '3':
                                break;
    
    
                            default:
                                printf("That is not a valid option at this time\n");
                                break;
                            }
                          }while (choice != '3');
                        }
    
    
                        display();
                        break;
                    }
    
    
                    break;
                case '2':
                    printf("Please input user id: ");
                    scanf("%s", temp);
                    for(i = 0; i < 20; i++){
                        if(strcmp(" ", mem[i].id) == 0)
                            {
                            strcpy(mem[i].id, temp);
    
    
                            printf("Please input user password: ");
                            strcpy(temp, "");
                            scanf("%s", temp);
                            strcpy(mem[i].pass, temp);
    
    
                            printf("Please input Email: ");
                            strcpy(temp, "");
                            scanf("%s", temp);
                            strcpy(mem[i].Email, temp);
    
    
                            printf("Please input GPA: ");
                            strcpy(temp, "");
                            scanf("%s", temp);
                            mem[i].GPA = atof(temp);
    
    
                            printf("Please input first name: ");
                            strcpy(temp, "");
                            scanf("%s", temp);
                            strcpy(mem[i].fName, temp);
    
    
                            printf("Please input last name: ");
                            strcpy(temp, " ");
                            scanf("%s", temp);
                            strcpy(mem[i].lName, temp);
    
    
                            printf("Please input gender: ");
                            strcpy(temp, " ");
                            scanf("%s", temp[0]);
                            strcpy(mem[i].gender, temp[0]);
    
    
                            printf("Please input age: ");
                            strcpy(temp," ");
                            scanf("%s", temp);
                            mem[i].age = atoi(temp);
    
    
                            printf("Please input SSN: ");
                            strcpy(temp, "");
                            scanf("%s", temp);
                            strcpy(mem[i].SSN, temp);
    
    
                            printf("Thank you!!!\n\n");
                            display();
                            break;
                        }
                    }
                    break;
                case '3':
                    break;
                default:
                    printf("%c is not a viable option at this time\n", choice);
                    break;
            }
        }while(choice != '3');
        printf("Goodbye %s!!!\n", mem[i].id );
    }
    
    
    void display()
    {
        printf("1. Log in\n");
        printf("2. Sign up\n");
        printf("3. Exit\n\n");
    }
    
    
    void Up_Date_Info(struct Members mem[20], int i)
    {
    
    
        char choice = '\0';
        char temp[20];
    
    
        printf("1. ID\n");
        printf("2. PASSWORD\n");
        printf("3. FIRST NAME\n");
        printf("4. LAST NAME\n");
        printf("5. EMAIL\n");
        printf("6. GPA\n");
        printf("7. GENDER\n");
        printf("8. AGE\n");
        printf("9. SSN\n");
    
    
        printf("What do you want to update?");
        scanf("%s", &choice);
    
    
        switch(choice)
        {
            case '1':
                printf("Please input your new ID: \n");
                strcpy(temp," ");
                scanf("%s", temp);
                strcpy(mem[i].id, temp);
    
    
                printf("Your new id is %s\n", mem[i].id);
                printf("Update is done!!!\n");
                break;
    
    
            case '2':
                printf("Please enter your new password:");
                strcpy(temp," ");
                scanf("%s", temp);
                strcpy(mem[i].pass, temp);
    
    
                printf("Your new password is %s\n", mem[i].pass);
                printf("Update is done!!!\n");
                break;
    
    
            case '3':
                printf("Please enter your new first name:");
                strcpy(temp," ");
                scanf("%s", temp);
                strcpy(mem[i].fName, temp);
    
    
                printf("Your new first name is %s\n", mem[i].fName);
                printf("Update is done!!!\n");
                break;
    
    
            case '4':
                printf("Please enter your new last name:");
                strcpy(temp," ");
                scanf("%s", temp);
                strcpy(mem[i].lName, temp);
    
    
                printf("Your new last name is %s\n", mem[i].lName);
                printf("Update is done!!!\n");
                break;
    
    
            case '5':
                printf("Please enter your new Email:");
                strcpy(temp," ");
                getchar();
                scanf("%s", temp);
                strcpy(mem[i].Email, temp);
    
    
                printf("Your new Email is %s\n", mem[i].Email);
                printf("Update is done!!!\n");
                break;
    
    
            case '6':
                printf("Please enter your new GPA:");
                strcpy(temp," ");
                scanf("%s", temp);
                mem[i].GPA = atof(temp);
    
    
                printf("Your new GPA is %s\n", mem[i].GPA);
                printf("Update is done!!!\n");
                break;
    
    
            case '7':
                printf("Please enter your new gender:");
                strcpy(temp," ");
                scanf("%s", temp);
                mem[i].gender = temp[0];
    
    
                printf("Your new gender is %s\n", mem[i].gender);
                printf("Update is done!!!\n");
                break;
    
    
            case '8':
                printf("Please enter your new age:");
                strcpy(temp," ");
                scanf("%s", temp);
                mem[i].age = atoi(temp);
    
    
                printf("Your new age is %s\n", mem[i].age);
                printf("Update is done!!!\n");
                break;
    
    
            case '9':
                printf("Please enter your new SSN:");
                strcpy(temp," ");
                scanf("%s", temp);
                strcpy(mem[i].SSN, temp);
    
    
                printf("Your new SSN is %s\n", mem[i].SSN);
                printf("Update is done!!!\n");
                break;
    
    
            default:
                printf("%c is not a valid option at this time.", choice);
                break;
        }
    }
    And here are the warnings:

    Code:
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c||In function 'main':|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|117|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|178|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|179|warning: passing argument 1 of 'strcpy' makes pointer from integer without a cast [enabled by default]|
    c:\program files (x86)\codeblocks\mingw\include\string.h|45|note: expected 'char *' but argument is of type 'char'|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|179|warning: passing argument 2 of 'strcpy' makes pointer from integer without a cast [enabled by default]|
    c:\program files (x86)\codeblocks\mingw\include\string.h|45|note: expected 'const char *' but argument is of type 'char'|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|43|warning: unused variable 'tempG' [-Wunused-variable]|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c||In function 'Up_Date_Info':|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|292|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'double' [-Wformat=]|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|302|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|312|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c||In function 'main':|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|205|warning: control reaches end of non-void function [-Wreturn-type]|
    ||=== Build finished: 0 error(s), 9 warning(s) (0 minute(s), 0 second(s)) ===|
    The one that I really do not understand the most is:
    Code:
    C\Homework8\Homework8.c|117|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]|
    temp is declared as a char but if I am reading this correctly, the warning says it is an int.
    Can someone explain what is going one with this please?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    33,201
    > warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]|
    What's wrong here?
    Code:
    printf("the string is %s", 42 );
    If you understand why this is wrong, then you can fix your warnings also.
    stahta01 likes this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    2,891
    Rebuild the code and post the current warnings.
    Your warnings posted do NOT match the code posted.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  4. #4
    Registered User
    Join Date
    Jul 2014
    Posts
    34
    Here are the current warnings:

    Code:
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c||In function 'main':|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|116|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|177|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|178|warning: passing argument 1 of 'strcpy' makes pointer from integer without a cast [enabled by default]|
    c:\program files (x86)\codeblocks\mingw\include\string.h|45|note: expected 'char *' but argument is of type 'char'|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|178|warning: passing argument 2 of 'strcpy' makes pointer from integer without a cast [enabled by default]|
    c:\program files (x86)\codeblocks\mingw\include\string.h|45|note: expected 'const char *' but argument is of type 'char'|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c||In function 'Up_Date_Info':|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|291|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'double' [-Wformat=]|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|301|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|311|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c||In function 'main':|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|204|warning: control reaches end of non-void function [-Wreturn-type]|
    ||=== Build finished: 0 error(s), 8 warning(s) (0 minute(s), 0 second(s)) ===|

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,063
    Quote Originally Posted by Ruger06
    format '%s' expects argument of type 'char *', but argument 2 has type 'int'
    Basically, this means that you have code along these lines:
    Code:
    int x;
    scanf("%s", x);
    Problem is, there is no scanf call in the code that you show that matches this mistake, hence stahta01 observed that "your warnings posted do NOT match the code posted", and this remains true for the warnings in post #4.

    That said, this is a mistake:
    Code:
    scanf("%s", &choice);
    choice is declared as a char, so &choice is a char*. This satisfies the type requirement, but %s is supposed to read and store a string. Hence, there must be space for the null character, so if you treat choice as a string, then it only string it can possibly be is the empty string. You probably should use %c instead of %s.

    Yet, this is also a mistake:
    Code:
    scanf("%s", temp);
    temp is declared as a char[20], so in this context it is converted to a char*. Excellent, you can read and store a string of up to 19 characters in length. However, you did not specify that the field width should be 19, hence the code is vulnerable to buffer overflow. Furthermore, you did not check the return value of scanf. Therefore, we would expect something like:
    Code:
    if (scanf("%19s", temp) == 1)
    {
        /* ... */
    }
    else
    {
        /* handle error */
    }
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    2,891
    Warnings with line number match the OP post.

    Code:
    E:\Test\Homework8\main.c: In function 'main':
    E:\Test\Homework8\main.c:129:29: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat]
    E:\Test\Homework8\main.c:201:25: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat]
    E:\Test\Homework8\main.c:202:25: warning: passing argument 1 of 'strcpy' makes pointer from integer without a cast [enabled by default]
    In file included from E:\Test\Homework8\main.c:9:0:
    c:\apps\mingw-4.7.1\bin\../lib/gcc/mingw32/4.7.1/../../../../include/string.h:45:39: note: expected 'char *' but argument is of type 'char'
    E:\Test\Homework8\main.c:202:25: warning: passing argument 2 of 'strcpy' makes pointer from integer without a cast [enabled by default]
    In file included from E:\Test\Homework8\main.c:9:0:
    c:\apps\mingw-4.7.1\bin\../lib/gcc/mingw32/4.7.1/../../../../include/string.h:45:39: note: expected 'const char *' but argument is of type 'char'
    E:\Test\Homework8\main.c: In function 'Up_Date_Info':
    E:\Test\Homework8\main.c:335:13: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'double' [-Wformat]
    E:\Test\Homework8\main.c:347:13: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat]
    E:\Test\Homework8\main.c:359:13: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat]
    E:\Test\Homework8\main.c: In function 'main':
    E:\Test\Homework8\main.c:231:1: warning: control reaches end of non-void function [-Wreturn-type]
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  7. #7
    Registered User
    Join Date
    Jul 2014
    Posts
    34
    Hello laserlight ;
    In response to your post, how do you suggest that I go about fixing the problem. I have no experience handling errors. My class never even touched on the subject. I have tried everything that I can think of to get this code to work with no luck. Any suggestion would be greatly appreciated.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,063
    Quote Originally Posted by Ruger06
    In response to your post, how do you suggest that I go about fixing the problem. I have no experience handling errors. My class never even touched on the subject. I have tried everything that I can think of to get this code to work with no luck. Any suggestion would be greatly appreciated.
    Well, I note that stahta01 pointed out that the problem with your post #4 was that the line numbers did not correspond to the line numbers in the code posted, but otherwise it was okay.

    What you should do is to take a look at the line indicated in the error/warning message. For example, for this warning:
    Code:
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|116|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]|
    The line is:
    Code:
    printf("Your gender is %s\n", mem[i].gender);
    Now, the line indicated says that the compiler detected the problem on this line. It does not always mean that the mistake is on that line; it could well be a mistake was made earlier, but the compiler could only detect it at that point. However, start by being open to the possibility that the mistake is indeed on that line.

    So, you read the warning message. It says "format '%s' expects argument of type 'char *', but argument 2 has type 'int'". Therefore, you look at the line. Indeed there is a '%s'. You notice that argument 2 is mem[i].gender. It turns out that mem[i].gender is a char, so maybe due to type promotion or something the compiler reported it as an int, but no matter, the point is that it is not a char*, but with the %s format specification, you should be passing a char*.

    To fix this, think: is the %s format specification correct, or is the mem[i].gender argument correct, or are both wrong? Obviously, you do indeed want to print the gender, therefore the mem[i].gender argument is correct, hence the %s format specification must be wrong. If you look up the correct format specification, you will find that it is %c. Change the %s to %s, re-compile, then work on the next warning/error.

    The key here is to be systematic: read the line number, read the text of the message, read your code. Do not be intimidated. Also, until you have sufficient skill, don't try to fix too many of them at the same time: sometimes, fixing one problem will fix many related problems, and at other times fixing one problem wrong out of many will make it harder to determine what went wrong with your fix.
    Matticus likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Jul 2014
    Posts
    34
    Ok laserlight;
    I take it that this line "Change the %s to %s, re-compile, then work on the next warning/error." was meant to say change %s to %c. Is this correct?

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,063
    Ah yes. Typo error.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #11
    Registered User
    Join Date
    Jul 2014
    Posts
    34
    Ok, here is new code with new warnings
    Code:
    /* Leslie Bauert
       CSE1311 HW 8
       Aug. 11, 2014
     */
    
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    
    struct Members
    {
        char fName[20];
        char lName[20];
        char Email[30];
        char id[20];
        char pass[20];
        char SSN[15];
        char gender;
        double GPA;
        int age;
    
    
    };
    
    
    void Up_Date_Info(struct Members mem[20],int i);
    void View_Info (struct Members mem[20], int i);
    void display();
    
    
    int main()
    {
        int i;
        struct Members mem[20];
        for(i = 0; i < 20; i++)
            {
                strcpy(mem[i].id, " ");
                strcpy(mem[i].pass, " ");
                strcpy(mem[i].Email, "             ");
                strcpy(mem[i].fName, " ");
                strcpy(mem[i].lName, " ");
                strcpy(mem[i].SSN, " ");
                //char gender = '\0';
            }
        char choice;
        char temp[20];
        char temppass[20] = "";
        i = 0;
    
    
         printf("Start Program\n");
         printf("1. Log in\n");
         printf("2. Sign up\n");
         printf("3. Exit\n");
    
    
        do
        {
    
    
            printf("What do you want to do: ");
            scanf("%c", &choice);
            printf("\n");
    
    
            switch (choice)
            {
                case '1':
                    printf("Please enter your id: ");
                    strcpy(temp, "");
                    scanf("%s", temp);
    
    
                    printf("Please enter your password: ");
                    strcpy(temppass, "");
                    scanf("%s", temppass);
                    getchar();
    
    
                    for (i = 0; i < 20; i++)
                    {
                        if (strcmp(temp, mem[i].id) != 0 || strcmp(temppass, mem[i].pass) != 0)
                        {
                            while ((strcmp(temp, mem[i].id) != 0 || strcmp(temppass, mem[i].pass) != 0))
                            {
                                if (strcmp(temp, mem[i].id) != 0)
                            {
                                printf("Please re-enter your id: ");
                                strcpy(temp, "");
                                scanf("%s", temp);
                            }
                            if (strcmp(temppass, mem[i].pass) != 0)
                            {
                                printf("Please re-enter your password: ");
                                strcpy(temppass, "");
                                scanf("%s", temppass);
                                getchar();
                            }
                            }
    
    
                            printf("\n");
                        }
    
    
                        if (strcmp(temp, mem[i].id) == 0 && strcmp(temppass, mem[i].pass) == 0)
                        {
                            printf("Hello %s!!!\n\n", mem[i].id);
                            do
                            {
                                printf("1. View User Account\n");
                                printf("2. Update User Account\n");
                                printf("3. Log out\n\n");
                                printf("What do you want to do?");
                                choice = '\0';
                                scanf("%c", &choice);
                                getchar();
                            switch (choice)
                            {
                            case '1':
                                printf("User id is: %s\n", mem[i].id);
                                printf("User password is: %s\n", mem[i].pass);
                                printf("Your first name is %s\n", mem[i].fName);
                                printf("Your last name is %s\n", mem[i].lName);
                                printf("Your Email is %s\n", mem[i].Email);
                                printf("Your GPA is %.1f\n", mem[i].GPA);
                                printf("Your gender is %c\n", mem[i].gender);
                                printf("Your age is %d\n", mem[i].age);
                                printf("Your SSN is %s\n", mem[i].SSN);
                                printf("\n");
                                break;
    
    
                            case '2':
                                Up_Date_Info(mem, i);
                                getchar();
                                break;
    
    
                            case '3':
                                break;
    
    
                            default:
                                printf("That is not a valid option at this time\n");
                                break;
                            }
                          }while (choice != '3');
                        }
    
    
                        display();
                        break;
                    }
    
    
                    break;
                case '2':
                    printf("Please input user id: ");
                    scanf("%s", temp);
                    for(i = 0; i < 20; i++){
                        if(strcmp(" ", mem[i].id) == 0)
                            {
                            strcpy(mem[i].id, temp);
    
    
                            printf("Please input user password: ");
                            strcpy(temp, "");
                            scanf("%s", temp);
                            strcpy(mem[i].pass, temp);
    
    
                            printf("Please input Email: ");
                            strcpy(temp, "");
                            scanf("%s", temp);
                            strcpy(mem[i].Email, temp);
    
    
                            printf("Please input GPA: ");
                            strcpy(temp, "");
                            scanf("%s", temp);
                            mem[i].GPA = atof(temp);
    
    
                            printf("Please input first name: ");
                            strcpy(temp, "");
                            scanf("%s", temp);
                            strcpy(mem[i].fName, temp);
    
    
                            printf("Please input last name: ");
                            strcpy(temp, " ");
                            scanf("%s", temp);
                            strcpy(mem[i].lName, temp);
    
    
                            printf("Please input gender: ");
                            strcpy(temp, " ");
                            scanf("%s", temp[i]);
                            strcpy(mem[i].gender, temp[i]);
    
    
                            printf("Please input age: ");
                            strcpy(temp," ");
                            scanf("%s", temp);
                            mem[i].age = atoi(temp);
    
    
                            printf("Please input SSN: ");
                            strcpy(temp, "");
                            scanf("%s", temp);
                            strcpy(mem[i].SSN, temp);
    
    
                            printf("Thank you!!!\n\n");
                            display();
                            break;
                        }
                    }
                    break;
                case '3':
                    break;
                default:
                    printf("%c is not a viable option at this time\n", choice);
                    break;
            }
        }while(choice != '3');
        printf("Goodbye %s!!!\n", mem[i].id );
    }
    
    
    void display()
    {
        printf("1. Log in\n");
        printf("2. Sign up\n");
        printf("3. Exit\n\n");
    }
    
    
    void Up_Date_Info(struct Members mem[20], int i)
    {
    
    
        char choice = '\0';
        char temp[20];
    
    
        printf("1. ID\n");
        printf("2. PASSWORD\n");
        printf("3. FIRST NAME\n");
        printf("4. LAST NAME\n");
        printf("5. EMAIL\n");
        printf("6. GPA\n");
        printf("7. GENDER\n");
        printf("8. AGE\n");
        printf("9. SSN\n");
    
    
        printf("What do you want to update?");
        scanf("%s", &choice);
    
    
        switch(choice)
        {
            case '1':
                printf("Please input your new ID: \n");
                strcpy(temp," ");
                scanf("%s", temp);
                strcpy(mem[i].id, temp);
    
    
                printf("Your new id is %s\n", mem[i].id);
                printf("Update is done!!!\n");
                break;
    
    
            case '2':
                printf("Please enter your new password:");
                strcpy(temp," ");
                scanf("%s", temp);
                strcpy(mem[i].pass, temp);
    
    
                printf("Your new password is %s\n", mem[i].pass);
                printf("Update is done!!!\n");
                break;
    
    
            case '3':
                printf("Please enter your new first name:");
                strcpy(temp," ");
                scanf("%s", temp);
                strcpy(mem[i].fName, temp);
    
    
                printf("Your new first name is %s\n", mem[i].fName);
                printf("Update is done!!!\n");
                break;
    
    
            case '4':
                printf("Please enter your new last name:");
                strcpy(temp," ");
                scanf("%s", temp);
                strcpy(mem[i].lName, temp);
    
    
                printf("Your new last name is %s\n", mem[i].lName);
                printf("Update is done!!!\n");
                break;
    
    
            case '5':
                printf("Please enter your new Email:");
                strcpy(temp," ");
                getchar();
                scanf("%s", temp);
                strcpy(mem[i].Email, temp);
    
    
                printf("Your new Email is %s\n", mem[i].Email);
                printf("Update is done!!!\n");
                break;
    
    
            case '6':
                printf("Please enter your new GPA:");
                strcpy(temp," ");
                scanf("%s", temp);
                mem[i].GPA = atof(temp);
    
    
                printf("Your new GPA is %f\n", mem[i].GPA);
                printf("Update is done!!!\n");
                break;
    
    
            case '7':
                printf("Please enter your new gender:");
                strcpy(temp," ");
                scanf("%c", temp[i]);
                mem[i].gender = temp[i];
    
    
                printf("Your new gender is %c\n", mem[i].gender);
                printf("Update is done!!!\n");
                break;
    
    
            case '8':
                printf("Please enter your new age:");
                strcpy(temp," ");
                scanf("%s", temp);
                mem[i].age = atoi(temp);
    
    
                printf("Your new age is %d\n", mem[i].age);
                printf("Update is done!!!\n");
                break;
    
    
            case '9':
                printf("Please enter your new SSN:");
                strcpy(temp," ");
                scanf("%s", temp);
                strcpy(mem[i].SSN, temp);
    
    
                printf("Your new SSN is %s\n", mem[i].SSN);
                printf("Update is done!!!\n");
                break;
    
    
            default:
                printf("%c is not a valid option at this time.", choice);
                break;
        }
    }
    
    
    /*
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c||In function 'main':|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|116|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|177|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|178|warning: passing argument 1 of 'strcpy' makes pointer from integer without a cast [enabled by default]|
    c:\program files (x86)\codeblocks\mingw\include\string.h|45|note: expected 'char *' but argument is of type 'char'|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|178|warning: passing argument 2 of 'strcpy' makes pointer from integer without a cast [enabled by default]|
    c:\program files (x86)\codeblocks\mingw\include\string.h|45|note: expected 'const char *' but argument is of type 'char'|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c||In function 'Up_Date_Info':|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|291|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'double' [-Wformat=]|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|301|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|311|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c||In function 'main':|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|204|warning: control reaches end of non-void function [-Wreturn-type]|
    ||=== Build finished: 0 error(s), 8 warning(s) (0 minute(s), 0 second(s)) ===|
    */
    Warnings:
    Code:
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c||In function 'main':|
    
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|177|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]|
    
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|178|warning: passing argument 1 of 'strcpy' makes pointer from integer without a cast [enabled by default]|
    c:\program files (x86)\codeblocks\mingw\include\string.h|45|note: expected 'char *' but argument is of type 'char'|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|178|warning: passing argument 2 of 'strcpy' makes pointer from integer without a cast [enabled by default]|
    c:\program files (x86)\codeblocks\mingw\include\string.h|45|note: expected 'const char *' but argument is of type 'char'|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c||In function 'Up_Date_Info':|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|298|warning: format '%c' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c||In function 'main':|
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|204|warning: control reaches end of non-void function [-Wreturn-type]|
    ||=== Build finished: 0 error(s), 5 warning(s) (0 minute(s), 0 second(s)) ===|
    The count is down to 5 warnings now but there is still the problem of
    Code:
    C:\Users\Leslie Bauert\Documents\Summer Programming in C\Homework8\Homework8.c|177|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]|
    I do not have a clue what is causing this.

  12. #12
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,063
    What is line 177?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  13. #13
    Registered User
    Join Date
    Jul 2014
    Posts
    34
    Stupid mistake . For got to end main with (return 0) this took care of one warning. Only 4 left. Is it possible that I left out a necessary header file?

  14. #14
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,063
    Quote Originally Posted by Ruger06
    Is it possible that I left out a necessary header file?
    Yes, it is possible. But to know whether you did or did not, you need to systematically go through the warnings and corresponding code to see if your conjecture has merit.

    Quote Originally Posted by Ruger06
    I do not have a clue what is causing this.
    You have two clues: the text of the warning message and the line number indicated. Look at the code, and you will have yet another clue.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  15. #15
    Registered User
    Join Date
    Jul 2014
    Posts
    34
    Changed
    Code:
    printf("Please input gender: ");
                            strcpy(temp, " ");
                            scanf("%s", temp[i]);
                            strcpy(mem[i].gender, temp[i]);
    
    //To this:
    
    printf("Please input gender: ");
                            strcpy(temp, " ");
                            scanf("%s", temp);
                            strcpy(mem[i].gender, temp);
    Now the program crashes when you enter the gender.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 03-23-2013, 01:44 PM
  2. Replies: 4
    Last Post: 03-12-2011, 05:59 PM
  3. Replies: 9
    Last Post: 05-28-2010, 10:11 AM
  4. Help on understanding the warning message
    By ssharish2005 in forum C Programming
    Replies: 3
    Last Post: 05-24-2007, 02:03 AM
  5. warning i've never seen
    By linuxdude in forum C Programming
    Replies: 5
    Last Post: 08-30-2006, 01:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21