Last active
August 29, 2015 13:57
-
-
Save kosaki/9560671 to your computer and use it in GitHub Desktop.
This file contains 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 <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; | |
} |
This file contains 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
# 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