diff options
author | Benjamin Chausse <benjamin@chausse.xyz> | 2022-09-24 12:30:31 -0400 |
---|---|---|
committer | Benjamin Chausse <benjamin@chausse.xyz> | 2022-09-24 12:30:31 -0400 |
commit | b1117af2d9167204585be3671ecabebadc1de1f5 (patch) | |
tree | 2a3bf6c5fd3bce32acbab5d410a21f3057550c15 | |
parent | 5355c5cc92a760b61b599a9116d9ecab5e800cd0 (diff) |
centralized formating header file
-rw-r--r-- | README.md | 16 | ||||
-rw-r--r-- | format.h | 56 | ||||
-rw-r--r-- | testData.h | 2 |
3 files changed, 65 insertions, 9 deletions
@@ -5,14 +5,14 @@ programing as well as basic algorithms. The project requires that we (the students) create a C library which doesn't rely on third party libraries to do the following things: -| Task | filename | Level | -| :------------------------------------ | :---------- | :------- | -| Spot characters in a string | `TODO` | Easy | -| Identify words which are palindromes | `TODO` | Easy | -| Calculate sines (using series) | `TODO` | Medium | -| Calculate cosines (using series) | `TODO` | Medium | -| Matrix addition | `TODO` | Hard* | -| Matrix multiplication | `TODO` | Hard* | +| Task | filename | Level | +| :------------------------------------ | :----------------- | :------- | +| Spot characters in a string | `findChar.h` | Easy | +| Identify words which are palindromes | `findPalindrome.h` | Easy | +| Calculate sines (using series) | `sine.h` | Medium | +| Calculate cosines (using series) | `cosine.h` | Medium | +| Matrix addition | `TODO` | Hard* | +| Matrix multiplication | `TODO` | Hard* | *This is the first programing APP. The word Hard is used very liberaly here. diff --git a/format.h b/format.h new file mode 100644 index 0000000..2f9c1b4 --- /dev/null +++ b/format.h @@ -0,0 +1,56 @@ +/* format.h + * ---------------------------------------------------------------------------- + * 'THE BEER-WARE LICENSE' (Revision 42): + * <benjamin@chausse.xyz> wrote this file. As long as you retain this notice + * you can do whatever you want with this stuff. If we meet some day, and you + * think this stuff is worth it, you can buy me a beer in return. + * Benjamin Chausse + * ---------------------------------------------------------------------------- + */ + +#define TRUE 1 +#define FALSE 0 +#define COUNT_OF( arr) (sizeof(arr)/sizeof(0[arr])) + +// Conversion table between uppercase and lowercase +const char caps[2][26] = { + {'A','B','C','D','E','F','G','H','I','J','K','L','M', + 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}, + {'a','b','c','d','e','f','g','h','i','j','k','l','m', + 'n','o','p','q','r','s','t','u','v','w','x','y','z'} +}; + +// Convert every character to lowercase +char * lower(char *str){ + int len = COUNT_OF(str); + for (int i=0; i<len; i++){ + // Change all letters to lowercase + for (int j=0;j<26;j++){ + if (str[i] == caps[0][j]) { + str[i] = caps[1][j]; + } + } + } + return str; +} + +char * trim(char *str){ + // Count the total number of spaces to define the new str size + int spc =0; + for (int i=0; i<COUNT_OF(str); i++){ + if (str[i] == ' '){ + spc++; + } + } + // Actually format the new string + char nstr[COUNT_OF(str)-spc+1]; + int j = 0; // index inside the new str (nstr) + for (int i=0; i<COUNT_OF(str); i++){ + if (str[i] != ' '){ + nstr[j] = str[i]; + j++; + } + } + nstr[COUNT_OF(nstr)-1] = '\0'; + return nstr; +} @@ -17,7 +17,7 @@ // - Trailing spaces -> sis, heightened, minim // - Spaces before the words -> sis, unholly, pop // - Non latin alphabet (greek & russian) -char *word[] = { +char *wrd[] = { "abba", "betrothed", "deified", "elevation", "genesis", "kayak", "murdum", " pop", "relinquish", "stats", "thirst", "abhorrent", "accentuated", "agoraphobia", " aibohphobia", "anemia", "bIb", "bittersweet", "bob", |