function to reduce duplicated code
| 32 | |
| 33 | // function to reduce duplicated code |
| 34 | void process_word(char ***words, int *wordCount, char *word, int wordIndex) |
| 35 | { |
| 36 | // Trim trailing spaces from the word |
| 37 | while (wordIndex > 0 && isspace((unsigned char)word[wordIndex - 1])) |
| 38 | { |
| 39 | wordIndex--; |
| 40 | } |
| 41 | // add word to array |
| 42 | word[wordIndex] = '\0'; |
| 43 | *words = realloc(*words, sizeof(char *) * (*wordCount + 1)); |
| 44 | if (*words == NULL) |
| 45 | { |
| 46 | fprintf(stderr, "Error: memory allocation failed\n"); |
| 47 | cleanup_argarray(words, wordCount); |
| 48 | exit(1); |
| 49 | } |
| 50 | (*words)[*wordCount] = word; |
| 51 | (*wordCount)++; |
| 52 | } |
| 53 | |
| 54 | int split_command(char *input, char ***words, int *wordCount) |
| 55 | { |
no test coverage detected