Rewrote inside_out(), make sure chars shift
[sigilutils.git] / basics.h
blob9b1f0a4081ae452fb48cb18372e6ee862cc13413
2 #ifndef BASICS_H
3 #define BASICS_H
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <ctype.h>
10 char* absorb_words (int count, char** string_list, int start_index)
12 char* result = calloc(sizeof(char), (count * 20));
13 for (int i = start_index; i < count; i++)
14 strcat(result, string_list[i]);
16 return result;
19 char* __upcase (char* original)
21 char* result = calloc(sizeof(char), strlen(original));
22 int index = 0;
23 while (original[index])
25 result[index] = toupper(original[index]);
26 index++;
29 return result;
32 char* strip_nonalpha (char* original)
34 int length = strlen(original);
35 char* result = calloc(sizeof(char), length);
37 int count = 0;
38 for (int i = 0; i < length; i++)
40 if (isalpha(original[i]))
42 result[count] = original[i];
43 count++;
47 return result;
50 char* strip_dupes (char* original)
52 int length = strlen(original);
53 char* upcased = __upcase(original);
54 char* result = calloc(sizeof(char), 26); // 26 unique characters in
55 // the english alphabet
56 int count = 0;
57 for (int i = 0; i < length; i++)
59 if (!strchr(result, (int) upcased[i]))
61 result[count] = upcased[i];
62 count++;
66 free(upcased);
67 return result;
70 char* string_process (char* string)
72 char* filtered = strip_nonalpha(string);
73 char* result = strip_dupes(filtered);
75 free(filtered);
76 return result;
79 #endif