Prompt user for last name as well
(Note: ...)
This commit is contained in:
12
main.c
12
main.c
@@ -2,10 +2,12 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char name[255];
|
char first[255], last[255];
|
||||||
printf("Enter your name: ");
|
printf("Enter your first name: ");
|
||||||
fgets(name, 255, stdin);
|
fgets(first, 255, stdin);
|
||||||
name[strlen(name)-1] = '\0'; /* remove the newline at the end */
|
first[strlen(first)-1] = '\0'; /* remove the newline at the end */
|
||||||
printf("Hello %s!\n", name);
|
printf("Now enter your last name: ");
|
||||||
|
gets(last); /* buffer overflow? what's that? */
|
||||||
|
printf("Hello %s %s!\n", first, last);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user