Skip to content

Instantly share code, notes, and snippets.

@bebyx
Created January 13, 2021 22:08
Show Gist options
  • Save bebyx/8b451199393803c7e502a40f486bae4c to your computer and use it in GitHub Desktop.
Save bebyx/8b451199393803c7e502a40f486bae4c to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
char* define_animal(char *noise);
int main() {
// Lions say 'Grr', Tigers say 'Rawr', Snakes say 'Ssss', and Birds say 'Chirp'
char noise[50];
char *token, *tmp;
const char delimiter[2] = " ";
fgets(noise, 50, stdin);
token = strtok(noise, delimiter);
while( token != NULL ) {
tmp = token;
printf( "%s ", define_animal(tmp));
token = strtok(NULL, delimiter);
}
return 0;
}
char* define_animal(char *noise) {
static char animal[10];
if (strstr(noise, "Grr") != NULL) {
strcpy(animal, "Lion");
return animal;
} else if (strstr(noise, "Rawr") != NULL) {
strcpy(animal, "Tiger");
return animal;
} else if (strstr(noise, "Ssss") != NULL) {
strcpy(animal, "Snake");
return animal;
} else if (strstr(noise, "Chirp") != NULL) {
strcpy(animal, "Bird");
return animal;
} else {
return "";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment