Skip to content

Instantly share code, notes, and snippets.

@jordansinger
Created December 18, 2015 03:37
Show Gist options
  • Save jordansinger/8203ae75affd889009e7 to your computer and use it in GitHub Desktop.
Save jordansinger/8203ae75affd889009e7 to your computer and use it in GitHub Desktop.
wrap.c
#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