Last active
August 29, 2015 14:11
-
-
Save mpatraw/c3fe0bd2440662023db9 to your computer and use it in GitHub Desktop.
Daily Programmer #193 Easy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ctype.h> | |
#include <stdio.h> | |
#include <string.h> | |
static struct { | |
const char *acronym; | |
const char *expansion; | |
} pairs[] = { | |
{"lol", "laugh out loud"}, | |
{"dw", "don't worry"}, | |
{"hf", "have fun"}, | |
{"gg", "good game"}, | |
{"brb", "be right back"}, | |
{"g2g", "got to go"}, | |
{"wtf", "what the fuck"}, | |
{"wp", "well played"}, | |
{"gl", "good luck"}, | |
{"imo", "in my opinion"}, | |
}; | |
static void print_expansion(const char *word) | |
{ | |
int i; | |
for (i = 0; i < sizeof(pairs) / sizeof(pairs[0]); ++i) { | |
if (!strcmp(word, pairs[i].acronym)) { | |
printf("%s", pairs[i].expansion); | |
return; | |
} | |
} | |
printf("%s", word); | |
} | |
int main(void) | |
{ | |
/* Should be long enough for most words. */ | |
char word[64]; | |
char *wptr = word; | |
char ch; | |
while (!feof(stdin)) { | |
ch = getc(stdin); | |
if (isalpha(ch)) { | |
*wptr++ = ch; | |
if (wptr >= word + 64) { | |
fprintf(stderr, "word longer than 64 chars.\n"); | |
return -1; | |
} | |
} else { | |
*wptr = '\0'; | |
print_expansion(word); | |
wptr = word; | |
putc(ch, stdout); | |
} | |
} | |
*wptr = '\0'; | |
print_expansion(word); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment