Empowering CS learners, aspiring programmers, and startups with AI, Data Science & Programming insights — scaling skills from learning foundations to enterprise-grade solutions.
Error: format specifies type ‘char’ but the argument has type ‘string’
#include<stdio.h>
#include<cs50.h>
int main(void)
{
string name = get_string ("what is your name\n");
scanf("%s", &name);
printf("%s",name);
}
On typing help50 make hello command, I get this suggestion:
hello.c:6:17: error: format specifies type 'char *' but the argument has type 'string *' (aka 'char **') [-Werror,-Wformat]
scanf("%s", &name);
~~ ^~~~~
Be sure to use the correct format code (e.g., %i for integers, %f for floating-point values, %s for strings, etc.) in your format string on line 6 of hello.c. ~/pset1/hello/ $
Do I need to remove string type and instead use char type. If so, why?
#include
#include
int main (void)
{
int number;
scanf ("enter a number %i", &number);
printf ("the number is %i", number);
}
Here is the result as I enter 44