Task 2: Hello, It's Me
Create me/hello.c. The program must ask the user for their name and print a
personal greeting.
For example:
What's your name? Adele
hello, Adele
For this exercise, you may assume that the name contains one word and no more than 99 characters.
Requirements
- Include
stdio.h. - Store the name in a
chararray. - Read the name with
scanfand a safe field width. - Print the name using
printfand the%sformat code. - End the output with a new line.
Starter code
#include <stdio.h>
int main(void)
{
char name[100];
// Ask for the user's name.
// Print the greeting.
}
Hint
A char array is already an address, so it does not need & when passed
to scanf with %s.
Compile and test
cc hello.c -o hello
./hello
Test at least three different names. Confirm that the output contains the name
entered by the user rather than the literal word name.
Continue with Task 3: Mario.