#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main(int argc, char* argv[])
{
char str[256] = "0000 11111 0000 111 00000 1111111 00000 11111111 000000 1111111\0";
int max = 256, max_pos = 0;
for (int i = 0; str[i] != '\0'; i++)
{
if (isspace(str[i]) || str[i+1] == '\0')
{
int k = i-1;
while (k >= 0 && !isspace(str[k])) k--;
if (abs((k+1)-i) < max) { max = abs((k+1)-i); max_pos = k+1; }
}
}
printf("str = %s\nmax_pos = %d max_len = %d\n",str,max_pos,max);
}