From b12812b91cb316321fa86d4b39735e151d0d96b9 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Fri, 15 Apr 2016 23:05:43 -0400 Subject: [PATCH] ex24 extra credit --- lcthw-remnants-2/ex24.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lcthw-remnants-2/ex24.c b/lcthw-remnants-2/ex24.c index 0d55588..e5da167 100644 --- a/lcthw-remnants-2/ex24.c +++ b/lcthw-remnants-2/ex24.c @@ -24,18 +24,25 @@ int main(int argc, char *argv[]) { Person you = {.age = 0}; int i = 0; + int rc = -1; char *in = NULL; printf("What's your First Name? "); in = fgets(you.first_name, MAX_DATA-1, stdin); check(in != NULL, "Failed to read first name."); + rc = sscanf(you.first_name, "%s", you.first_name); + check(rc > 0, "Failed to strip first name."); + printf("What's your Last Name? "); in = fgets(you.last_name, MAX_DATA-1, stdin); check(in != NULL, "Failed to read last name."); + rc = sscanf(you.last_name, "%s", you.last_name); + check(rc > 0, "Failed to strip last name."); + printf("How old are you? "); - int rc = fscanf(stdin, "%d", &you.age); + rc = fscanf(stdin, "%d", &you.age); check(rc > 0, "You have to enter a number."); printf("What color are your eyes:\n"); @@ -57,8 +64,8 @@ int main(int argc, char *argv[]) printf("----- RESULTS -----\n"); - printf("First Name: %s", you.first_name); - printf("Last Name: %s", you.last_name); + printf("First Name: %s\n", you.first_name); + printf("Last Name: %s\n", you.last_name); printf("Age: %d\n", you.age); printf("Eyes: %s\n", EYE_COLOR_NAMES[you.eyes]); printf("Income: %f\n", you.income);