Определить количество символов в словах строки - C (СИ)
Формулировка задачи:
ребят,подскажите как посчитать количиство символов в слове в строке, нужно посчитать поличество 3 слов, вот что у меня пока что получилось,но считивает только первое слово.Подскажите где ошыбка
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<iostream>
int main(void)
{
char str[] ="banana apple cat";
char*pch;
printf("the lenght of string=%d\n",strlen(str));
printf ("Splitting string "%s"into tokens:\n",str);
pch = strtok(str," ");
while (pch !=NULL)
{
printf("%s\n",pch);
printf("the lenght of string=%d\n",strlen(str));
for(int j=0;j < length;j++)
pch=strtok (NULL, " ");
}
return 0;
}Решение задачи: «Определить количество символов в словах строки»
textual
Листинг программы
#include <stdio.h>
#include <string.h>
#define DELIM " ,.?!\n\t"
int main(void)
{
char str[] ="banana apple cat";
printf("the lenght of string=%d\n",strlen(str));
printf ("Splitting string %s into tokens:\n",str);
for (char* pch = strtok(str, DELIM); pch; pch = strtok(NULL, DELIM))
printf("the lenght of word %s =%u\n", pch, strlen(pch));
return 0;
}