warning: format '%c' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat]|

I've taken a break from c++ and I trying to learn c. What I think is happening here is that it's somehow promoting the char to an int because the argument that I provided is a char. What do you think is the problem? Oh, since I'm learning c, do you see anything here that is a no-no in terms of bad practice.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
#include <ctype.h>

void skipLine()
{
    scanf("%*[^\n]");   /* Skip to the End of the Line */
    scanf("%*1[\n]");   /* Skip One Newline */
}

int main()
}
  int x, args;
  char r = 'y';

    while(toupper(r) != 'N')
    {
        printf("Enter an integer: ");
        if (( args = scanf("%d", &x)) == 0)
        {
            printf("Error: not an integer\n");
            skipLine();
            continue;
        }
        else
        {
            if(args == 1)
            {
                printf("Read in %d\n", x);
                skipLine();

                printf("\nWould you like to enter another number? [y/n]");
                scanf("%c", &r); // The warning is here.
            }
        }
    }
}
Last edited on
The 'r' is a char. The function, however, wants an address of a memory location where it should write a char to.
See http://www.cplusplus.com/forum/beginner/151602/
Why does your link redirect me back here?
All right, all I needed to do was add the &. Thanks for the help.
But just like people have said, scanf is really bad for input.
Topic archived. No new replies allowed.