Tady to mas opravene a trosku okomentovane:
#include<iostream>
using namespace std;
struct zamestnanci
{
char jmeno[20];
int vek;
char prace[1000];
}clen[32000]; // celkem dost, radeji to placni na heap
int main()
{
int p_zamest;
const int b=36000;//nevidim vyuziti
int c=0; // celkem zbytecne
int i=0; // int i=1 pole se v C/C++ indexuje od 0
char o; // char o[36000] nechapu proc pole??
cout<<"zadejte pocet zamestnancu: ";
cin>>p_zamest;
cin.get();
o='a';
for(i;i<p_zamest && toupper(o)=='A';i++)
{
cout<<"jmeno zamestnance:";
cin.getline(clen[i].jmeno,20);
cout<<"vek:";
cin>>clen[i].vek;
cin.get();
cout<<"popis prace:";
cin.getline(clen[i].prace,20);
cout<<"chcete zadat dalsiho zamestnance? a/n";
cin>>o;
cin.get();
}
// kontrolni vypis
for(int j=0; j < i; j ++)
{
cout << clen[j].jmeno << endl;
cout << clen[j].vek << endl;
cout << clen[j].prace << endl;
}
cin.get();
return 0;
}
A tady mas jeste me 2 reseni, protoze s pouzitim STL se Ti velice usnadni zivot:
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
class CZamestnanec
{
public:
char jmeno[30];
size_t vek;
char prace[1000];
};
typedef std::vector<CZamestnanec> v;
int main(int argc, char *argv[])
{
size_t pocet, i;
cout << "Zadej pocet zamestnancu: "; cin >> pocet;
cin.get();
v prace;
for(i=0; i<pocet; i++)
{
char c;
CZamestnanec z;
cout << "Zadej jmeno: "; cin.getline(z.jmeno, 30);
cout << "Zadej vek: "; cin >> z.vek; cin.get();
cout << "Zadej praci: " ; cin.getline(z.prace, 1000);
prace.push_back(z);
cout << "prejete si zadat dalsiho zamestnance? a/n"; cin >> c;
cin.get();
if('A' != toupper(c)) break;
}
for(int j=0; j <prace.size(); j++)
{
cout << "jmeno: "<< prace[j].jmeno<< endl;
cout << "vek: "<< prace[j].vek << endl;
cout << "prace: " << prace[j].prace << endl;
}
cin.get();
return 0;
}
Anebo mam jeste ono druhe reseni, rekl bych v duchu OOP a C++:
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
class CZamestnanec
{
public:
std::string jmeno;
size_t vek;
std::string prace;
};
class CPrace: public std::vector<CZamestnanec>
{
public:
void nacti();
void vypis() const;
};
void CPrace::nacti()
{
int pocet;
cout << "Zadej pocet: "; cin >> pocet; cin.get();
for(int i=0; i<pocet; i++)
{
char c;
CZamestnanec z;
cout << "Zadej jmeno: "; getline(cin, z.jmeno);
cout << "Zadej vek: "; cin >> z.vek; cin.get();
cout << "Zadej praci: " ; getline(cin, z.prace);
push_back(z);
cout << "prejete si zadat dalsiho zamestnance? a/n"; cin >> c;
cin.get();
if('A' != toupper(c) ) break;
}
}
void CPrace::vypis() const
{
for(const_iterator i=begin(); i!=end(); i ++)
{
cout << "jmeno: "<< i->jmeno<< endl;
cout << "vek: "<< i->vek << endl;
cout << "prace: " << i->prace << endl;
}
}
int main(int argc, char *argv[])
{
CPrace pr;
pr.nacti();
pr.vypis();
cin.get();
system("PAUSE");
return EXIT_SUCCESS;
}
P.S.: Zkus si neco precist o praci s polem..