Created
December 18, 2015 03:37
-
-
Save jordansinger/8203ae75affd889009e7 to your computer and use it in GitHub Desktop.
wrap.c
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 "string.h" | |
#include "stdlib.h" | |
#include "stdio.h" | |
char *wrap(char *s, char wchars[]) { | |
char *result = malloc(strlen(s) + 3); | |
result[0] = wchars[0]; | |
strcat(result, s); | |
result[strlen(s) + 1] = wchars[1]; | |
return result; | |
} | |
int main(int argc, char const *argv[]) { | |
char *p1 = wrap("testing", "()"); | |
printf("p1 = %s\n", p1); | |
// | |
// Output: p1 = (testing) | |
char *p2 = wrap(p1, "<>"); | |
printf("p2 = %s\n", p2); | |
// | |
// Output: p2 = <(testing)> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment