#include <stdio.h> #include <string.h> #include <stddef.h> int main() { char str[5002]; while (fgets(str, sizeof(str), stdin) != NULL) { str[strcspn(str,"\n")] = '\0'; int lengthofstr = strlen(str); char *last_space = strrchr(str, ' '); if(last_space != NULL) { ptrdiff_t lastwordLength = (char *)str + lengthofstr - last_space - 1; printf("%td", lastwordLength); } else { size_t lastwordLength = strlen(str); printf("%zu", lastwordLength); } } return 0; }