#include #include #include #include // b int stringsum(char* str) { int sum = 0; char c; int i; for (i = 0; (c = str[i]); ++i) { if (c >= 'A' && c <= 'Z') sum += c - 'A' + 1; else if (c >= 'a' && c <= 'z') sum += c - 'a' + 1; else return -1; } return sum; } // c int distance_between(char* str, char ch) { int first = -1; char c; int i; for (i = 0; (c = str[i]); ++i) { if (c != ch) continue; if (first == -1) first = i; else return i - first; } return -1; } // d char* string_between(char* str, char ch) { int start = -1; char c; int i; for (i = 0; (c = str[i]); ++i) { if (c != ch) continue; if (start == -1) { start = i; } else { char* res = malloc(i - start + 1); memcpy(res, str + start + 1, i - start - 1); res[i - start - 1] = '\0'; return res; } } return NULL; } // e char** split(char* str) { char delim = ' '; int len = 0; int start = 0; char** res = NULL; char c; int i; for (i = 0; (c = str[i]); ++i) { if (c != delim) continue; len += 1; res = realloc(res, sizeof(*res) * len); char* s = malloc(i - start + 1); memcpy(s, str + start, i - start); s[i - start] = '\0'; res[len - 1] = s; start = i + 1; } // Add the last item, and null len += 2; res = realloc(res, sizeof(*res) * len); char* s = malloc(i - start + 1); memcpy(s, str + start, i - start); s[i - start] = '\0'; res[len - 2] = s; res[len - 1] = NULL; return res; } // g void stringsum2(char* str, int* res) { int sum = 0; char c; int i; for (i = 0; (c = str[i]); ++i) { if (c >= 'A' && c <= 'Z') sum += c - 'A' + 1; else if (c >= 'a' && c <= 'z') sum += c - 'a' + 1; else { *res = -1; return; } } *res = sum; }