#need help with an error occuring in code

67 messages · Page 1 of 1 (latest)

wet aurora
#

argument of type "int" is incompatible with parameter of type "const char *"

river sailBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

wet aurora
#

the error message is given in text as shown above

#

any help is very much appreciated

elder mist
#

printf takes a format first and then it takes the values, example coming:

elder mist
#
int a = 1;
int b = 2;

printf("%d + %d = %d", a, b, a + b);
wet aurora
#

ohh

#

so we cant just print variables directly

elder mist
#

indeed

wet aurora
# elder mist indeed
int a =30;
int b = a+5;
int c =b+1, e;
printf ("%d", a , "%d" , b , "%d", c , "%d", e)

#

is this the correct way?

elder mist
#

no, first comes the format as the first argument, then come the values

wet aurora
#

hmm

elder mist
#

printf(formatString, ...values)

#

also, what are you trying to achieve with int c =b+1, e;

wet aurora
#
int a =30;
int b = a+5;
int c =b+1, e;
printf ("%d , %d , %d, %d", a , b, c, e)

elder mist
#

yes printf is correct there

#

don't forget your ; tho

wet aurora
elder mist
#

ah, that's indeed what that does

wet aurora
wet aurora
elder mist
#

nw

river sailBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

wet aurora
# elder mist nw
#include<stdio.h>

int main(){
    int a=30;
    int b=a+5;
    int c= b+1, e;
    printf("%d , %d , %d, %d", a , b, c, e);
}```
it is still showing the same problem tho
#

argument of type "int" is incompatible with parameter of type "const char *"

elder mist
#

I mean it compiles for me

#

are you actually building?

wet aurora
elder mist
#

your intellisense might not yet have caught up

wet aurora
#

im a beginner

elder mist
#

how are you running it

wet aurora
#

gcc

elder mist
#

show your process

wet aurora
elder mist
#

are you running it or is it just showing that before running

wet aurora
wet aurora
elder mist
#

gcc must be run in the same folder where the c file is

#

or you must specify the full path to the folder where it is + the c file

wet aurora
#

im typing the name wrong

#

its instruction.c

#

💀

wet aurora
#

the e variable dont have a value assigned

#

why is e coming as 4200816?

elder mist
#

well yesn't, you didn't initialize it
it did make space on your memory for it.
that means that whatever was there before you made space for it in memory will be shown

#

i.e. useless garbage

#

hence why you'd always want to set a value before using a variable

#

or you'll get something random

wet aurora
#

so like the space it was assigned to it

#

previously haad 4200816 stored in it

#

and thats why it got printed//

#

?

elder mist
#

ye

#

something like that

wet aurora
#

thanks once again for the help!

elder mist
#

np

tropic yoke