Note that there are some explanatory texts on larger screens.

plurals
  1. POGCC compile error: format ‘%c’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat]
    text
    copied!<p>Ok, I'm a noob with C, but I think the code is basic and straightforward. This program is for a college assignment, and is supposed to have the 'isdigit()' function in it. Here is the code</p> <pre><code>//by Nyxm #include &lt;stdio.h&gt; #include &lt;ctype.h&gt; main() { char userChar; int userNum, randNum; srand(clock()); printf("\nThis program will generate a random number between 0 and 9 for a user to guess.\n"); /*I changed it from '1 to 10' to '0 to 9' to be able to use the isdigit() function which will only let me use a 1 digit character for an argument*/ printf("Please enter a digit from 0 to 9 as your guess: "); scanf("%c", userChar); if (isdigit(userChar)) { userNum = userChar - '0'; randNum = (rand() % 10); if (userNum == randNum) { printf("Good guess! It was the random number.\n"); } else { printf("Sorry, the random number was %d.\n", randNum); } } else { printf("Sorry, you did not enter a digit between 0 and 9. Please try to run the program again.\$ } } </code></pre> <p>When I try to compile, I get the following error</p> <pre><code>week3work1.c: In function ‘main’: week3work1.c:14:2: warning: format ‘%c’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat] </code></pre> <p>What on earth is going on? I am desperate for help. Any help at all. I am seriously about to just give up on this program. Why is it saying it expects argument of 'char *' when my textbook shows that "%c" is for regular ole 'char'? I am using nano, gcc, and Ubuntu if that makes any difference.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload