Почему выводит только одну структуру и не выводит количество людей, живущих на введенной с клавиатуры улице?
Массив структур содержит информацию о 30 студентов: фамилия; имя; номер группы; адрес прописки; пол. Считать данные с файла и подсчитать количество студентов, которые прописаны на заданной с клавиатуры улице.
#include<iostream>
#include<Windows.h>
#include<fstream>
#include <string>
#include<cstring>
using namespace std;
struct Students
{
char name[20];
char surname[20];
char adress[40];
char gender[15];
int numberofgroup;
};
bool ReadFile(Students*& arr_Students, int& size)
{
arr_Students = new Students[100];
size = 0;
ifstream fin("Students.txt");
while (fin >> arr_Students[size].name)
{
fin >> arr_Students[size].surname;
fin >> arr_Students[size].adress;
fin >> arr_Students[size].gender;
fin >> arr_Students[size].numberofgroup;
++size;
if (size >= 100)
break;
}
return true;
}
void print(Students* arr_Students, int size)
{
for (int i = 0; i < size; i++)
{
cout << arr_Students[i].name << endl;
cout << arr_Students[i].surname << endl;
cout << arr_Students[i].adress << endl;
cout << arr_Students[i].gender << endl;
cout << arr_Students[i].numberofgroup << endl;
cout << endl;
}
char street[40];
cout << "enter street: ";
cin >> street;
for (int i = 0; i < size; i++)
{
if (strcmp(street, arr_Students[i].adress) == 0)
cout << "Number of student who live in street: " << size << endl;
}
}
int main()
{
SetConsoleOutputCP(1251);
SetConsoleCP(1251);
bool ReadFile(Students * &arr_Students, int& size);
void print(Students * arr_Students, int size);
int size;
Students* arr_Students;
if (ReadFile(arr_Students, size))
print(arr_Students, size);
else
cout << "Error opening file!" << endl;
cin.get();
return 0;
}