I keep getting the same error when I try to compile it
#include <stdio.h>
int main(){
char name[25];
int age;
printf("\nwhat is your name: ");
scanf("%s", &name);
printf("what is your age: ");
scanf("%d", &age);
printf("\nyour name is %s", name);
printf("\nand your age is %d", age);
return 0;
}
>Solution :
I assume this is the "error" you are receiving:
main.c: In function 'main':
main.c:9:9: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[25]' [-Wformat=]
scanf("%s", &name);
You should try to read and understand it, as compiler warnings usually are quite clear. This one tells you that the %s in the line scanf("%s", &name); expects a char *, that is, a pointer to a char, whereas you have supplied a char (*)[25] which is a pointer to an array of 25 chars.
Basically, the argument &name has the wrong type. The name of the array, in this case the name is a pointer to the first element of the array, and you should not put an ampersand (&) (the address of …) operator when giving it as an argument to scanf.
The correct call would be: scanf("%s", name);.
I also strongly suggest you to avoid using scanf as a user-interface function. See this.