I have set up a couple of printf statements to find the problem and I am still clueless.
Basically I am creating the array plane to contain 12 struct seats.
Then I assign each struct inside of plane data. Everything looks good at this point.
Then I pass that array to numberEmptySeats and all of the sudden plane[0].seatID is lost in the sauce instead of being the 1 it was originally assigned.
Please help me understand why this is happening.
-------------Current Output-------------
1
Entering numberEmptySeats
1123456789101112
Seats Available: 12
------------Desired Output-------------
1
Entering numberEmptySeats
1
Seats Available: 12
Code:
#include<stdio.h>
#include<string.h>
#define SEATS 12
struct seat {
int seatID;
int reserved;
char firstName[20];
char lastName[20];
};
void resetPlane(struct seat ar[],int seats);
void numberEmptySeats(struct seat ar[],int seats);
int main()
{
struct seat plane[SEATS];
resetPlane(plane,SEATS);
printf("%d\n",plane[0].seatID);
numberEmptySeats(plane,SEATS);
}
void resetPlane(struct seat ar[],int seats)
{
int i;
for(i=0;i<seats;i++)
{
ar[i].seatID = i+1;
ar[i].reserved = 0;
strcpy(ar[i].firstName,"Unassigned");
strcpy(ar[i].lastName,"Unassigned");
}
}
void numberEmptySeats(struct seat ar[],int seats)
{
int i,j=0;
printf("Entering numberEmptySeats\n");
printf("%d",ar[0].seatID);
for(i=0;i<seats;i++)
{
if (ar[i].reserved == 0)
{
printf("%d",ar[i].seatID);
j++;
}
}
printf("\nSeats Available: %d\n",j);
}