-
Notifications
You must be signed in to change notification settings - Fork 3
/
5-13.c
39 lines (28 loc) · 808 Bytes
/
5-13.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#define MAX_LINES 50
#define MAX_LINE_LENGTH 100
int main(int argc, char **argv) {
char input[50][100];
int line = 0;
int index = 0;
input[line][index] = getchar();
while (input[line][index] != EOF && line <= MAX_LINES) {
while (index < MAX_LINE_LENGTH && input[line][index] != '\n' && input[line][index] != EOF)
input[line][++index] = getchar();
if (input[line][index] == '\n') {
input[line][index] = '\0';
line++;
index = -1;
}
}
input[line][index] = '\0';
int needed_lines = atoi(argv[1]);
while (needed_lines + 1 > 0) {
printf("%s\n", input[line]);
line--;
needed_lines--;
}
return 0;
}