From 66a82e135bba5c60aa2604e8393665757be7b944 Mon Sep 17 00:00:00 2001 From: tmeissner Date: Tue, 20 Oct 2015 23:20:12 +0200 Subject: [PATCH] Add first exercises of chapter 04 --- c_primer_plus/chapter04/01.c | 18 ++++++++++++++++++ c_primer_plus/chapter04/02.c | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 c_primer_plus/chapter04/01.c create mode 100644 c_primer_plus/chapter04/02.c diff --git a/c_primer_plus/chapter04/01.c b/c_primer_plus/chapter04/01.c new file mode 100644 index 0000000..f5195a2 --- /dev/null +++ b/c_primer_plus/chapter04/01.c @@ -0,0 +1,18 @@ +#include + + + +int main (void) { + + char first_name[20]; + char last_name[20]; + + printf("Your first name: "); + scanf("%s", first_name); + printf("Your last name: "); + scanf("%s", last_name); + printf("Your name is %s, %s\n", last_name, first_name); + + return 0; + +} diff --git a/c_primer_plus/chapter04/02.c b/c_primer_plus/chapter04/02.c new file mode 100644 index 0000000..bd4cd3e --- /dev/null +++ b/c_primer_plus/chapter04/02.c @@ -0,0 +1,19 @@ +#include +#include + + + +int main (void) { + + char first_name[20]; + + printf("Your first name: "); + scanf("%s", first_name); + + printf("Your name: \"%s\"\n", first_name); + printf("Your name: \"%20s\"\n", first_name); + printf("Your name: \"%*s\"\n", (int)(strlen(first_name)+3), first_name); + + return 0; + +}