C: bob
This commit is contained in:
43
c/bob/src/bob.c
Normal file
43
c/bob/src/bob.c
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <ctype.h>
|
||||
#include "bob.h"
|
||||
#include <stdio.h>
|
||||
|
||||
char*answers[] = {
|
||||
"Whatever.",
|
||||
"Sure.",
|
||||
"Whoa, chill out!",
|
||||
"Calm down, I know what I'm doing!",
|
||||
"Fine. Be that way!"
|
||||
};
|
||||
|
||||
char *hey_bob(char *w)
|
||||
{
|
||||
int yell=2, question=0, empty=4, text=0;
|
||||
for (;*w; w++) {
|
||||
if (!isspace(*w)) {
|
||||
empty=0;
|
||||
if (isalpha(*w)) text=2;
|
||||
if (islower (*w)) yell=0;
|
||||
question=*w=='?'? 1: 0;
|
||||
}
|
||||
}
|
||||
return answers[(text&yell)|question|empty];
|
||||
}
|
||||
|
||||
|
||||
/* See GNUmakefile below for explanation
|
||||
* https://github.com/braoult/exercism/blob/master/c/templates/GNUmakefile
|
||||
*/
|
||||
#ifdef UNIT_TEST
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
int arg=1;
|
||||
resistor_band_t i[2];
|
||||
|
||||
for (; arg<ac-1; ++arg, ++arg) {
|
||||
*i=atoi(av[arg]);
|
||||
*(i+1)=atoi(av[arg+1]);
|
||||
printf("color(%d, %d)=%d\n", i[0], i[1], color_code(i));
|
||||
}
|
||||
}
|
||||
#endif
|
18
c/bob/src/bob.h
Normal file
18
c/bob/src/bob.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef BOB_H
|
||||
#define BOB_H
|
||||
|
||||
char *hey_bob(char *greeting);
|
||||
|
||||
/* See GNUmakefile below for explanation
|
||||
* https://github.com/braoult/exercism/blob/master/c/templates/GNUmakefile
|
||||
*/
|
||||
#if defined UNIT_TEST || defined DEBUG
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef TESTALL
|
||||
#undef TEST_IGNORE
|
||||
#define TEST_IGNORE() {}
|
||||
#endif
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user