Untitled
unknown
c_cpp
2 years ago
1.4 kB
10
Indexable
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <string.h>
#define LEN 1000
#define DELIM " .,:;!?-_()[]"
// в текстовом файле дан многострочный текст, найти количество строк, в которых есть как минимум 3 слова, содержащих более 3 цифр
int main()
{
SetConsoleCP (1251);
SetConsoleOutputCP (1251);
FILE *fp = fopen ("data.txt", "r" );
if ( fp == NULL )
{
puts ("Ошибка чтения файла!");
return EXIT_FAILURE;
}
char str [ LEN ];
int cntStr = 0;
while ( fgets ( str, LEN, fp ) != NULL )
{
int cntDigit = 0;
char* word = strtok ( str, DELIM );
while ( word != NULL )
{
int i;
for ( i = 0; i < strlen ( word [ i ] ); i++)
if (isdigit ( word [ i ] ) )
++cntDigit;
}
if ( cntDigit >= 3 )
++cntStr;
}
fclose (fp);
if ( !cntStr )
puts ("Строки, содержащие минимум 3 слова, содержащих более 3 цифр, отсутствуют!");
else
printf ("Кол-во строк содержащих минимум 3 слова, содержащих более 3 цифр = %d\n", cntStr );
return 0;
}
Editor is loading...
Leave a Comment