Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <ctype.h>
- #define NMAX 1000
- #define NULL_CHECK(p) if (p == NULL) return p;
- char *pheasant(char *s) {
- char *res = NULL;
- char *token = strtok(s, " ");
- int n = strlen(token) + 2;
- res = calloc(n, sizeof(char));
- strcpy(res, token);
- res[n-2] = '-';
- NULL_CHECK(res);
- token = strtok(NULL, " ");
- while (token) {
- if (tolower(token[0]) == tolower(res[n - 4]) && tolower(token[1]) == tolower(res[n - 3])) {
- n += strlen(token) + 1;
- res = realloc(res, sizeof(char) * n);
- NULL_CHECK(res);
- strcat(res, token);
- strcat(res, "-");
- }
- token = strtok(NULL, " ");
- }
- res[n - 2] = 0;
- return res;
- }
- int main(void) {
- static char s[NMAX] = "Fazan antic";
- char *res = pheasant(s);
- if (res == NULL) {
- fprintf(stderr, "alloc error!\n");
- exit(-1);
- }
- puts(res);
- free(res);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement