Skip to content

Instantly share code, notes, and snippets.

@kosaki
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kosaki/9560671 to your computer and use it in GitHub Desktop.
Save kosaki/9560671 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#define BUFSIZE 80
int main(int argc, char *argv[]) {
char employee[BUFSIZE] = "John,Doe,john@example.com";
char name[BUFSIZE] = {0};
char surname[BUFSIZE] = {0};
char *email;
size_t length;
/* Extract the information: */
memccpy(name, employee, ',', BUFSIZE);
length = strlen(name);
memccpy(surname, employee + length, ',', BUFSIZE);
length += strlen(surname);
email = employee + length;
/* Compose the new entry: */
strcat(employee, surname);
strcpy(employee, name);
strcat(employee, email);
/* Print the result: */
puts(employee);
return 0;
}
# gcc -rdynamic -g -o employee employee.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment