Jan 18, 2015 at 8:14pm UTC
I need to transfer the content from the file text.txt to file sort.txt .
The data in the text.txt is "struct" (info about people)but the same data needs to be sorted by the name and sent to sort.txt by using a function .I be gratfull if someone can help me
Jan 18, 2015 at 9:36pm UTC
Show us what you have so far.
Jan 19, 2015 at 9:58am UTC
void sort1(int n)
{
// n= num of people
int i, j;
int temp_int;
string temp_string;
long long temp_long_long;
ifstream input("text.txt");
ofstream output("sort.txt");
n=n-1;
j=0;
while (!input.eof())
{
input>>aplikant[j].prezime;
input>>aplikant[j].ime;
input>>aplikant[j].maticenbroj;
input>>aplikant[j].datum_na_aplikacija;
input>>aplikant[j].licna_karta;
input>>aplikant[j].pasos;
input>>aplikant[j].vozacka_dozvola;
j++;
}
for (i=0; i<j; i++)
for(int k =(i+1); k < j; k++)
if (aplikant[i].prezime < aplikant[k].prezime)
{
temp_string= aplikant[i].ime;
aplikant[i].ime = aplikant[k].ime;
aplikant[k].ime = temp_string;
temp_string= aplikant[i].prezime;
aplikant[i].prezime = aplikant[k].prezime;
aplikant[k].prezime = temp_string;
temp_long_long = aplikant[i].maticenbroj;
aplikant[i].maticenbroj = aplikant[k].maticenbroj;
aplikant[k].maticenbroj = temp_long_long;
temp_int = aplikant[i].datum_na_aplikacija;
aplikant[i].datum_na_aplikacija = aplikant[k].datum_na_aplikacija;
aplikant[k].datum_na_aplikacija = temp_int;
temp_string = aplikant[i].licna_karta;
aplikant[i].licna_karta = aplikant[k].licna_karta;
aplikant[k].licna_karta = temp_string;
temp_string = aplikant[i].pasos;
aplikant[i].pasos = aplikant[k].pasos;
aplikant[k].pasos = temp_string;
temp_string = aplikant[i].vozacka_dozvola;
aplikant[i].vozacka_dozvola = aplikant[k].vozacka_dozvola;
aplikant[k].vozacka_dozvola = temp_string;
}
for(i=0; i<j-1; i++)
{
output<<aplikant[i].ime;
output<<endl;
output<<aplikant[i].prezime;
output<<endl;
output<<aplikant[i].maticenbroj;
output<<endl;
output<<aplikant[i].datum_na_aplikacija;
output<<endl;
output<<aplikant[i].licna_karta;
output<<endl;
output<<aplikant[i].pasos;
output<<endl;
output<<aplikant[i].vozacka_dozvola;
output<<endl;
}
Jan 19, 2015 at 1:25pm UTC
can you give me specific answer im beginner so i dont understand much
Jan 19, 2015 at 2:06pm UTC
i dont know why but it doesnt work it shows a lot of errors, any other idea
Jan 19, 2015 at 2:30pm UTC
i corected most of it but i dont know what to do with line 52 it says ISO C++ forbids declaration of āpā with no type
Jan 19, 2015 at 2:57pm UTC
Ah, it is just a common for loop with slightly different C++11 syntax. Just iterate over a vector like you would normally.
And I strongly suggest to upgrade to modern C++ standard.