#include <stdio.h>
int main()
{
char name[31];
printf("Name: ");
scanf("%s", name);
printf("Hello, %s!\n", name);
return 0;
}
|
- This program takes a string as an input and then redisplays it.
- What is a string? It is stream of characters. It could
be letters, punctiation marks, or spaces, or a mix between them.
- Since string is a stream of character, we define it like the above.
This time we define a variable name that can hold up to
31 characters.
- However, since C/C++ requires the characters terminated with a terminator code,
the net-effect is we can only store 30 characters.
- Note: Actually, this declaration defines an array of 31 characters. We will discuss array later.
|