Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
#include<stdio.h>
 
int main() 
{
   int a, b, c , suma;
   scanf("%d %d" "%d", &a, &b , &c);
   suma = a + b +c;
   printf("%d+%d+%d=%d",suma);
   return(0);
}
    i'm new to c and i m getting this error "format ‘%d’ expects a matching ‘int’ argument" i don t understand why i am trying for 24h to solve this and i cant

What I have tried:

i tried everything i just can t figure it out pls help me
Posted
Updated 30-Oct-22 0:36am

1 solution

Look at your code:
C
printf("%d+%d+%d=%d",suma);
The format string is %d+%d+%d=%d which means that printf expects four parameters to follow that: one for each of the %d codes in the format specification. You provide only one: suma so the compiler is saying "Hey! Where is the rest of it?"
You probably wanted this:
C
printf("%d+%d+%d=%d", a, b, c, suma);
You should expect to get syntax errors like this every day, probably many times a day while you are coding - we all do regardless of how much experience we have! Sometimes, we misspell a variable, or a keyword; sometimes we forget to close a string or a code block. Sometimes the cat walks over your keyboard and types something really weird. Sometimes we just forget how many parameters a method call needs.

We all make mistakes.

And because we all do it, we all have to fix syntax errors - and it's a lot quicker to learn how and fix them yourself than to wait for someone else to fix them for you! So invest a little time in learning how to read error messages, and how to interpret your code as written in the light of what the compiler is telling you is wrong - it really is trying to be helpful!

So read this: How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors[^] - it should help you next time you get a compilation error!
 
Share this answer
 
v2
Comments
Greg Utas 30-Oct-22 9:56am    
I went straight to C++, bypassing C, so I don't know much about printf. But I'd surprised if the compiler analyzed the string argument to printf to see if the variadic argument list was too short or contained the wrong types. I'd expect that to show up at run-time, as error messages from printf itself.
OriginalGriff 30-Oct-22 11:15am    
Some do, or at least a warning - gdb for example:

https://www.onlinegdb.com/online_c_compiler
merano99 1-Nov-22 5:30am    
Visual Studio analyzes the string argument of printf very precisely, both the number and the variable type are checked. I am rather surprised that this did not always work with every compiler. At runtime, on the other hand, nothing is checked, then the bytes are displayed that are on the stack, or otherwise in the expected places. The output is then either random, or with %s it can also crash.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900