|
CS256 - Principles of Structured Design
Fall 2021
|
Displaying ./code/h2sol/name.c
/*
name.c - get a name from the user, then output "Hello, <whatever name was put in>!"
and a new line to the terminal.
*/
#include <stdio.h>
int main(){
char name[30];
/*
Hint: Above, we've declared a character array named "name" with enough
room for 30 characters. When declaring an array, the number inside
the brackets indicates how many individual characters we can fit
inside the array
*/
printf("Who is this? "); //use printf to print a statement asking the user "Who is this? "
scanf("%s", name); //use scanf to get the persons name
/*
Hint: To tell scanf to expect a string, you'd use the %s format string
Also, unlike integers, if you are using scanf to read things into a
string, you do not need an & in front of the variable.
*/
printf("Hello, %s!\n", name);//then just print Hello and whatever name was entered.
return 0;
}
|