#include <stdio.h>
#include <string.h>
#include <ctype.h>
int shortest_word_length(const char *str) {
char buffer[1024];
strncpy(buffer, str, sizeof(buffer));
buffer[sizeof(buffer) - 1] = '\0'; // ensure null-termination
int min_len = 0;
// Tokenize by spaces, tabs, and newlines
char *token = strtok(buffer, " \t\n");
while (token != NULL) {
int len = strlen(token);
if (min_len == 0 || len < min_len) {
min_len = len;
}
token = strtok(NULL, " \t\n");
}
return min_len;
}
int main(void) {
const char *text = "Find the shortest word length in this string";
int result = shortest_word_length(text);
printf("Shortest word length: %d\n", result);
return 0;
}
/*
run:
Shortest word length: 2
*/