Hi, I have to write an address book using structs for a class. I have 90% of the code done, but I am having trouble ordering it. It is supposed to read in 10 entries from a file and then sort them by last name. All the information also has to be swapped. I am using Microsoft VC++ 6. I would appreciate any input on what might be wrong with this program. Thanks for the help. :)
#include <iostream>
#include <string>
#include <fstream>
#include <algorithm>
using namespace std;
struct student
{
string first_name;
string last_name;
string phone_number;
string age;
int month;
int day;
int year;
};
student log[100];
//double uslessfunction1(student log[].first_name,student log[].last_name,student log[].phone_number);
void uslessfunction1(student log[],ifstream infile,int x);
//double uslessfunction2(student log[].age,student log[].month,student log[].day,student log[].year);
void uslessfunction2(student log[],ifstream infile,int x);
void main()
{
double num=0,x=0,counter=0;
ifstream infile;
ofstream outfile;
infile.open("database.txt");
outfile.open("output.txt");
while(!infile.eof()){
{ counter=counter+1;
// uslessfunction1(log[].first_name,log[].last_name,log[].phone_number);
uslessfunction1(log[x],infile,x);
// uslessfunction2(log[].age,log[].month,log[].day,log[].year);
uslessfunction2(log[x],infile,x);
x=x+1;
}
for (x=0;x<counter;x++)
sort(log[x].first_name,log[x].first_name,10);
for (x=0;x<counter;x++)
outfile<<log[x].last_name<<", "<<log.first_name<<endl<<log[x].phone_number<<endl<<log[x].month<<"/"<<log[x].day<<"/"<<log[x].year<<endl;
}
//double uslessfunction1(student log[].first_name,student log[].last_name,student log[].phone_number)
void uslessfunction1(student log[],ifstream infile,int x)
{
infile>>log[x].first_name;
infile>>log[x].last_name;
infile>>log[x].phone_number;
}
//double uslessfunction2(student log[].age,student log[].month,student log[].day,student log[].year)
void uslessfunction2(student log[],ifstream infile,int x)
{
infile>>log[x].age;
infile>>log[x].month,log[x].day,log[x].year;
}