-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathjungle_camping.c
71 lines (61 loc) · 1.36 KB
/
jungle_camping.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void split(char const *str, const char delim, char out[][6], int *count)
{
const char *token;
int i = 0;
token = strtok((char *) str, &delim);
while (token != NULL)
{
strcpy(out[i], token);
token = strtok(NULL, &delim);
i++;
}
*count = i;
}
char* get_animals(char noises[])
{
char noisesSplit[100][6];
int count;
split(noises, ' ', noisesSplit, &count);
char* animals = malloc(sizeof(char) * 1000);
char *ptr = animals;
const char *sep = "";
for (int i = 0; i < count; i++)
{
char *animal;
if (strcmp(noisesSplit[i], "Rawr") == 0)
{
animal = "Tiger";
}
else if (strcmp(noisesSplit[i], "Chirp") == 0)
{
animal = "Bird";
}
else if (strcmp(noisesSplit[i], "Ssss") == 0)
{
animal = "Snake";
}
else if (strcmp(noisesSplit[i], "Grr") == 0)
{
animal = "Lion";
}
else
{
animal = "";
}
ptr += sprintf(ptr, "%s%s", sep, animal);
sep = " ";
}
return animals;
}
int main()
{
char noises[1000];
fgets(noises, sizeof(noises), stdin);
char* animals = get_animals(noises);
printf("%s", animals);
free(animals);
return 0;
}