@@ 1,12 1,40 @@
#include <stdio.h>
+#define MAX_CHARACTERS 20
+
/*
* William Culhane
* Classwork 12, CSCI 112
* Wed Jun 2 12:19:42 PM MDT 2021
*/
+unsigned char count_chars(char word[MAX_CHARACTERS + 1]) {
+ // Check if string is done
+ if (word[0] == '\0') {
+ return 0;
+ } else {
+ // Create a new word with the first character removed
+ char new_word[MAX_CHARACTERS];
+ for (unsigned char i = 0; i < MAX_CHARACTERS; i++) {
+ // Check if last copied character was null
+ if (word[i] == '\0') {
+ break;
+ } else {
+ new_word[i] = word[i + 1];
+ }
+ }
+ // Count the characters in the word with a character missing
+ return (count_chars(new_word) + 1);
+ }
+}
+
int main(void) {
- // TODO
- return(0);
+ char word[MAX_CHARACTERS + 1];
+ printf("Enter a word (max length %i characters)> ", MAX_CHARACTERS);
+ scanf("%s", word);
+
+ unsigned char length = count_chars(word);
+ printf("Length: %hhu\n", length);
+
+ return (0);
}