Have you considered using the std::sort function? Also, you should be using std::string's instead of char arrays.
Your current sorting functions only attempt to sort the data in the birthyear and surname fields, they do not affect the remainder of the data for the structs you are working with. For example, you may sort the birthyears, but the original names associated with those birthyears may belong with a different array index.
Code:
struct persona
{
char vards[15]; // name
char uzvards[15]; // Surname
int gads; // birth year
} pers[3];
...
void pecu (persona pers[]) // This doesn't works... It's sorting by surname
{
char temp[15];
for(int i=0; i<3 - 1; i++)
for(int j=0; j<3 - 1; j++)
if (pers[j].uzvards>pers[j+1].uzvards)
{
temp = pers[j].uzvards;
pers[j].uzvards = pers[j+1].uzvards;
pers[j+1].uzvards = temp;
}
}
Comparisons using character array's and assignment of character arrays don't work like you may think they do. This is a big reason your sort function does not work. You need to be using the strcmp and strcpy functions to perform these tasks. This is why it is much better to use a string which does work like this.
An example using std::strings and the std::sort function.
Code:
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;
struct persona
{
string vards;
string uzvards;
int gads;
};
class sort_by_surname
{
public:
inline bool operator()(const persona& per1, const persona& per2)
{
// Can do this with strings but not with char arrays.
return per1.uzvards < per2.uzvards;
}
};
int main()
{
persona pers[3];
// Get data into pers array.
...
// Sort the pers array by surname.
sort( pers, pers+3, sort_by_surname() );
return 0;
}