Skip to content

Instantly share code, notes, and snippets.

@limdingwen
Created November 19, 2016 04:11
Show Gist options
  • Save limdingwen/d0209c05f950a0505fd25a8f4a9c767e to your computer and use it in GitHub Desktop.
Save limdingwen/d0209c05f950a0505fd25a8f4a9c767e to your computer and use it in GitHub Desktop.
Babify
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char** argv) {
const int EXIT_OK = 0;
const int EXIT_BADUSAGE = -1;
if (argc != 2) {
printf("Usage: babify [STRING]\n");
return EXIT_BADUSAGE;
}
char* message = argv[1];
char* newMessage = malloc(strlen(message) + 1); // Plus one for null terminator
for (int i = 0; i < strlen(message); i++) {
char msgChar = message[i];
char newMsgChar;
if (msgChar == 'r' || msgChar == 'l') newMsgChar = 'w';
else newMsgChar = msgChar;
newMessage[i] = newMsgChar;
}
newMessage[strlen(message)] = 0; // Null terminator
printf("%s\n", newMessage);
free(newMessage);
return EXIT_OK;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment