~learax/csci112-2021-william-culhane

a17b7fc9babd3651b208b1a2a2b349630bfa85e7 — William Culhane 3 years ago 957f95b
classwork12: Finish assignment
1 files changed, 30 insertions(+), 2 deletions(-)

M classwork/classwork12/classwork12.c
M classwork/classwork12/classwork12.c => classwork/classwork12/classwork12.c +30 -2
@@ 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);
}