Вывести количество слов, длина которых не менее z - C (СИ)

Узнай цену своей работы

Формулировка задачи:

//---------------------------------------------------------------------------
 
#include <vcl.h>
#include <conio.h>
#include <stdio.h>
#pragma hdrstop
 
//---------------------------------------------------------------------------
 
#pragma argsused
int str_A(char);
void main()
{int M;
char str[256];
printf("Vvedite text: \n");
gets(str);
M=str_A(str[256]);
printf("M=%d", M);
getch();
}
int str_A(char str)
{int m=1, k=0, z;
printf("Vvedite z: \n");
scanf("%d", z);
char c=' ';
do {
if(c==' ' || c=='.')
{if(k==1)
m++;
k=0;}
else if(c==getchar());
while (k>=z);
k++;
}
while(c!='.');
return(m-1);
}

Решение задачи: «Вывести количество слов, длина которых не менее z»

textual
Листинг программы
#include <stdio.h>
#include <string.h>
 
#define DELIM " \t\n"
 
size_t words_count(char * str, const char * delim, size_t minlength){
    return ( str = strtok(str, delim) ) ? ( strlen(str) >= minlength ) + words_count(NULL, delim, minlength) : 0;
}
 
int main(void) {
    size_t nMinLength;
    char buf[BUFSIZ];
    
    while ( printf("Min length: ") && scanf("%u%*c", &nMinLength) == 1 && nMinLength
           && printf("String: ") && scanf("%[^\n]", buf) == 1 ) {
        printf("%u words is length of %u or more characters.\n\n", words_count(buf, DELIM, nMinLength), nMinLength);
    }
    
    return 0;
}

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

14   голосов , оценка 4.286 из 5
Похожие ответы