Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C
#include<stdio.h>
#include<stdbool.h>
main()
{
	int age;
	char name;
	printf("what is your name? ");
	scanf("%s",&name);
	printf("what is your age? ");
	scanf("%d",&age);
    printf("you're name is %s and you're age is %d.", name , age);
    return 0;
}


What I have tried:

i have tried all the ways i could but i still not able to get the last print statement.
Posted
Updated 10-Jan-22 20:13pm
v2
Comments
jeron1 10-Jan-22 12:00pm    
You have defined name as a single character, it should be an array of characters, large enough for the longest name you expect plus 1 for the null terminator.
Richard Deeming 10-Jan-22 12:19pm    
Aside from the code errors, it's "your name", not "you're name". :)

"Your" is the possessive - the thing belonging to you.

"You're" is a contraction of "You are".

"You are name is ..." and "you are age is ..." are not valid English.

C++
char name;
Is what is wrong with your code. char is not a string but a byte sized integer.
you need to change that declaration to
C++
char name[50];
That will be a character array that can hold 49 characters plus a null terminator.
 
Share this answer
 
Comments
CPallini 11-Jan-22 2:09am    
5.
Maciej Los 11-Jan-22 6:54am    
5
See, for instance: Strings in C (With Examples)[^].
 
Share this answer
 
Comments
Maciej Los 11-Jan-22 6:54am    
5
CPallini 11-Jan-22 6:56am    
Thank you!

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