-1

I keep getting one bug in the terminal which says:

warning: format specifies type 'char *' but the argument has type 'int' [-Wformat]
    scanf("%c", namehumaninput);
           ~~   ^~~~~~~~~~~~~~

The course I am taking is saying that all I need to do is have a char variable and thats it, use that with nothing else but clearly something is wrong. Here is the code I am having trouble with:

    //Lesson 9
    int inputage;
    double gpainput;
    char namehumaninput;
    printf("Wat ur age?\n");
    scanf("%d", &inputage); // scanf(); is how you do an input. You MUST have & behind a variable after a %d!!
    printf("You are %d years old\n", inputage);
    printf("Was yo GPA?\n");
    scanf("%lf", &gpainput); // %lf is for double variables when using scanf() but using printf() it uses %s for variables. Confusing, I know.
    printf("Your GPA is %f\n", gpainput);
    printf("Wos yo name now that ive asked yo fo yo gpa and age\n");
    scanf("%c", namehumaninput); // %c is universal for both
    printf("Really? Yo name is %c?\n", namehumaninput);

I have the stdio and stdlib libraries imported and am using MacOS.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
Skibi OS
  • 17
  • 1
  • 2
    You seem to know that you need to pass pointers as arguments to the `scanf` function, as you do it in other places. Why don't you do it here? Why do you think it's different with characters and the `%c` format? – Some programmer dude Mar 04 '23 at 09:48
  • Also, please see the next comment, and [scanf() leaves the newline char in the buffer](https://stackoverflow.com/questions/5240789/scanf-leaves-the-new-line-char-in-the-buffer). – Weather Vane Mar 04 '23 at 09:49
  • 1
    Also, before your next question, change the format from `"%c"` to `" %c"` (note the leading space). – Some programmer dude Mar 04 '23 at 09:49

1 Answers1

1

This call of scanf

scanf("%c", namehumaninput);

you need to rewrite at least

scanf(" %c", &namehumaninput);

The leading space in the format string allows to skip white space characters in the input stream and you need to provide a pointer to a character as the second argument expression.

However this call allows to enter only a single character.

If you want to enter a word then you should write for example

char namehumaninput[20];
//...

scanf("%19s", namehumaninput);
printf("Really? Yo name is %s?\n", namehumaninput);
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335