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 the printf statement in order to let the scanf 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;
}