Project 2 - Greeter ๐ฌ#
For our second project, lets make a program that greets the user.
It should ask the user for their first name and then print a response!
Ex.
> What is your first name?
> Joe
> Hello Joe, nice to meet you!
For this project, letโs assume the maximum length of someoneโs first name is 63 characters.
Tasks ๐ฏ#
Print the question.
Hint โ
You can print something by writing
printf("the stuff I want to print");
. If this seems unfamiliar to you, then check out the hello_wordprintf section.Donโt forget the
\n
at the end of theprintf
statement in order to let thescanf
to detect user input on the next line!
Solution โ
#include <stdio.h> int main() { printf("What is your name?\n"); return 0; }
Get user input for their first name.
Hint โ
You can get a string input into a variable from a user by writing
scanf("%s", &string_variable_name);
. If this seems unfamiliar to you, then check out the variablesscanf section.
Solution โ
#include <stdio.h> int main() { char first_name[64] = ""; printf("What is your first name?\n"); scanf("%s", first_name); return 0; }
Print a greeting, including the userโs first name.
Hint โ
You can print a string variable by writing
printf("%s", string_variable_name);
. If this seems unfamiliar to you, then check out the variablesmore_printf section.
Solution โ
#include <stdio.h> int main() { char first_name[64] = ""; printf("What is your first name?\n"); scanf("%s", first_name); printf("Hi %s, nice to meet you!", first_name); return 0; }