Browse Source

Add first exercises of chapter 04

master
T. Meissner 9 years ago
parent
commit
66a82e135b
2 changed files with 37 additions and 0 deletions
  1. +18
    -0
      c_primer_plus/chapter04/01.c
  2. +19
    -0
      c_primer_plus/chapter04/02.c

+ 18
- 0
c_primer_plus/chapter04/01.c View File

@ -0,0 +1,18 @@
#include <stdio.h>
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;
}

+ 19
- 0
c_primer_plus/chapter04/02.c View File

@ -0,0 +1,19 @@
#include <stdio.h>
#include <string.h>
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;
}

Loading…
Cancel
Save