В файле содержится информация о студентах колледжа в виде: фамилии_им `я__отделение_группа (год обучения и буква). Определить количество студентов в данной группе — C++(Си)

#include <iostream>
#include <clocale>
#include <conio.h>
#include <io.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
 
void main ()
{
setlocale(LC_CTYPE, "rus");
FILE *f1=fopen("file.txt","r+");
        if(f1==NULL)
        {
        cout<<"Нет такого файла"<<endl;
        exit(1);
        }
char str[1024];
char gr[20];
int counter=0;
cout<<"Введите группу";
cin>>gr;
while(!feof(f1))
        {
                fgets(str,1023,f1);
                if(strstr(str,gr))counter++;
        }
cout<<"В группе "<<counter<<" студент(ов)"<<endl;
fclose(f1);
}

Leave a Comment