Since I was not making myself clear, here is the full program. ANYONE tell me what is wrong and how to correct it. I would really appreciate it. If you can show me some code examples. That would really help.
Code:
/* person.h */
#ifndef _PERSON_H
#define _PERSON_H
#include <stdio.h>
typedef struct {
int month;
int day;
int year;
} date;
typedef struct {
char lastName[25];
char firstName[25];
char middleInitial[1];
date dob;
} person;
#define N 100
#define FALSE 0
#define TRUE 1
int getInfo (person array[], int num_elements);
void ssort (person x[], int count);
void reverse (person x[], int count);
void printList (person x[], int num_elements);
int isInOrder (person x[], int num_elements);
int findmax (person x[], int count);
void swap (person * firstElement, person * secondElement);
#endif
/* main.c */
#include "person.h"
int main()
{
person x[N];
int count;
count = getInfo (x, N);
if (isInOrder (x, num_elements)) printf ("\nIts in order. \n");
else ssort (x, num_elements);
reverse(x, num_elements);
printList (x, num_elements);
return 0;
}
/* the input file, i am compiling on a unix machine */
smith 3 10 1956
johnson 4 2 1970
sharp 6 14 1964
sharp 5 9 2000
marion 4 3 1900
/* getInfo.c function */
#include "person.h"
int getInfo (person array[], int num_elements)
{
int count = 0;
while (count < num_elements)
{
if (scanf("%s%s%s%d%d%d", array[count].lastName, &array[count].dob.month, &array[count].dob.day,
&array[count].dob.year) == EOF) break;
count++;
}
return count;
}
/* isInOrder.c function */
#include "person.h"
int isInOrder (person x[], int num_elements)
{
int counter = 0;
while (counter < num_elements - 1)
{
if (x[counter] > x[counter + 1]) return FALSE;
counter++;
}
return TRUE;
}
/* ssort.c selection sort function */
#include "person.h"
void ssort (person x[], int count)
{
int counter;
while (count--)
{
counter = findmax (x, count);
swap (&x[counter], &x[count]);
}
}
/* swap.c function */
void swap (person * firstElement, person * secondElement)
{
int tempElement = *firstElement;
*firstElement = *secondElement;
*secondElement = tempElement;
}
/* findmax.c function */
#include "person.h"
int findmax (person x[], int count)
{
int maxind = 0;
int counter = 1;
while (counter <= count)
{
if (x[counter] > x[maxind]) maxind = counter;
counter++;
}
return maxind;
}
/* reverse.c function */
#include "person.h"
void reverse (person x[], int count)
{
int * p = &x[0];
int * q = p + count - 1;
while (p < q)
{
swap (p,q);
p++;
q--;
}
}
/* printList.c function */
#include "person.h"
void printList (person x[], int num_elements)
{
int * p = &x[0];
printf("\n");
while (p <= &x[num_elements - 1])
{
printf (%s %d\n" *p);
p++;
}
}
There is too many compile errors to list. The point I am trying to make is am I passing the elements of the struct correctly? Obviously I am not or it would compile with no errors and run. If you can some rework of at least on of my functions would hlep with the correct code. Thank You all for looking and helping.