C - scanf,printf name and age program
54,190
when you use scanf
, %c
is intended to get a single character. If you want to get a string, you need to use %s
.
Also, in C langage, string are just char arrays. So you need to declare a char array.
#include <stdio.h>
int main ()
{
char yourname[100];
int yourage;
printf("Whats your name?\t");
scanf("%s",yourname); //i let you read the doc to avoid overflow :)
printf("How old are you?\t");
scanf("%d",&yourage);
printf("You are %d years old and your name is %s \n\n\n",yourage,yourname);
system("pause");
return(0);
}
Author by
Spiros Kmaris
Updated on July 09, 2022Comments
-
Spiros Kmaris almost 2 years
#include <stdio.h> int main () { char yourname; int yourage; printf("Whats your name?\t"); scanf("%c",&yourname); printf("How old are you?\t"); scanf("%d",&yourage); printf("You are %d years old and your name is %c\n\n\n",yourage,yourname); system("pause"); return(0); }
I want this program to ask for the username and age, and then print them..