Cześć, dlaczego funkcja 'szukajRasy' ciągle zwraca "Nie znaleziono rasy" ?
Jak posortować tablicę wg. rasy?
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
struct Kot
{
char imie[10];
char rasa[20];
int wiek;
float waga;
};
std::vector<Kot> wczytajDane(std::ifstream& Plik);
void wyswietlDane(const std::vector<Kot>& wektor);
std::vector<Kot> wczytajDane(std::ifstream& Plik)
{
std::vector<Kot> Koty;
Kot kot;
while (Plik >> kot.imie >> kot.rasa >> kot.wiek >> kot.waga)
{
Koty.push_back(kot);
}
return Koty;
}
void wyswietlDane(const std::vector<Kot>& wektor)
{
for (const auto& k : wektor)
{
std::cout << k.imie << " " << k.rasa << " " << k.wiek << " " << k.waga << " " << "\n";
}
}
void szukajRasy(Kot tabela[], std::string r)
{
bool czy_znaleziono;
for (int i = 0; i < tabela.; i++)
{
czy_znaleziono = (tabela[i].rasa == r);
if (czy_znaleziono)
{
std::cout << r << tabela[i].imie;
}
}
if (czy_znaleziono == false)
{
std::cout << "\nNie znaleziono rasy";
}
}
int main()
{
Kot Koty[8]{};
std::ifstream Plik;
Plik.open("kotki.txt");
if (!Plik.is_open())
{
std::cout << "Plik nie moze zostac otwarty. \n";
std::cin.get();
exit(1);
}
wyswietlDane((wczytajDane(Plik)));
std::string rasa;
std::cout << "\nPodaj rase: ";
std::cin >> rasa;
szukajRasy(Koty,rasa);
std::cout << "\n-------------------------\n";
std::cin.ignore();
std::cin.get();
return EXIT_SUCCESS;
}