-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopypre.c
48 lines (40 loc) · 882 Bytes
/
copypre.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
40
41
42
43
44
45
46
47
48
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
static int ENTRIES = 20;
int main(int argc, char *argv[]){
char **usCity = (char **)malloc(ENTRIES * sizeof(char *));
int cityPop[20];
int cityCount = 0;
char *line;
size_t size;
for(int i = 0; i < ENTRIES; i++){
usCity[i] = NULL;
}
while(1){
if(getline(&line, &size, stdin) == EOF){
break;
}
else{
usCity[cityCount] = (char *)malloc(sizeof(char) * (size + 10));
strncpy(usCity[cityCount], line, size);
if(getline(&line, &size, stdin) == EOF){
break;
}
else if(atoi(line) > 15){
cityPop[cityCount++] = atoi(line);
}
else{
free(usCity[cityCount]);
}
}
}
//for(int i = 0; i < cityCount; i++){
int i = 0;
while(usCity[i] != NULL){
if(cityPop[i] > 15)
printf("%s", usCity[i++]);
}
return(0);
}