I'm writing my first more serious program in C and I'm stuck. I need to sort this list to different, separate files so it will look like this:
BE30B Berlin 2014-04-02 Gale 02
BE30B Berlin 2014-04-02 Dobbs 15
OS43K Oslo 2014-04-03 Malik 34
BE30B Berlin 2014-04-02 Hatton 09
OS43K Oslo 2014-04-03 Lowe 21
OS43K Oslo 2014-04-03 Smith 03
BE30B Berlin 2014-04-02 Chapman 13
OS43K Oslo 2014-04-03 Murphy 41
BE30B Berlin 2014-04-02 Dawkins 19
Output:
BE30B.txt
Berlin 2014-04-02
02 Gale
09 Hatton
13 Chapman
15 Dobbs
19 Dawkins
I don't have an idea how to start writing it. I'm not too good at programming, I normally do html/css. My functions currently look like this and it prints the whole list on the screen.
struct Booking // creating a structure
{
char number[6];
char dest[30];
char date[11];
char name[20];
int seat;
};
struct Bkg
{
struct Booking res;
struct Bkg *next;
};
struct Bkg *head = NULL;
void add_on_top( char* argnumber, char* argdest, char* argdate, char* argname, int argseat)
{
struct Bkg *temp=(struct Bkg*) malloc (sizeof(struct Bkg));
strcpy(temp->res.number, argnumber);
strcpy(temp->res.dest, argdest);
strcpy(temp->res.date, argdate);
strcpy(temp->res.name, argname);
temp->res.seat = argseat;
temp->next = head;
head = temp;
}
void insert( char* argnumber, char* argdest, char* argdate, char* argname, int argseat)
{
struct Bkg *head1 = head;
if (head != NULL) {
while (head1->next != NULL)
{
head1 = head1->next;
}
struct Bkg *temp = (struct Bkg*) malloc (sizeof(struct Bkg));
strcpy(temp->res.number, argnumber);
strcpy(temp->res.dest, argdest);
strcpy(temp->res.date, argdate);
strcpy(temp->res.name, argname);
temp->res.seat = argseat;
temp->next = NULL;
head1->next = temp;
}
else
add_on_top( argnumber, argdest, argdate, argname, argseat);
}
If someone could help me, I'd be very grateful. I just don't know how to sort it by the symbol, I can do the rest.
Symbol is the flight number: BE30B.
I didn't add main because there's not much going on there, I have struct Booking temp;
, I open a file with reservation and read it, then process it using function fscanf and use my function insert(temp.number, temp.dest, temp.date, temp.name, temp.seat);
Writing a code in C is not my choice, this is something my school required only for this semester.