Hi there,
As the title says, I'm having an issue passing an array of structures to a function.The structure reads and tokenises information from a text file. I then need to do things with that data using several different functions. Here's my code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct{
char carID[4];
char carType[8];
int engineSize;
char bodyType[9];
int numSeats;
char transType[9];
int mileage;
char available;
} cars_t;
int main()
{
cars_t cars[8];
char line[100];
char line2[100];
char *nextWordPtr;
int count = 0;
FILE *ptr_cars;
ptr_cars = fopen("cars.txt", "r");
while ( fgets ( line, sizeof line, ptr_cars ) != NULL )
{
strcpy(line2, line);
nextWordPtr = strtok(line2,";");
strcpy(cars[count].carID, nextWordPtr);
and so on for each struct variable...
}
int choice = 0;
while(choice != 7)
{
printf("1.\n2.\n3.\n4.\n5.\n6.\n7.\n");
scanf("%d", &choice);
if(choice == 3) listrented(cars_t cars[]);
}
return 0;
}
When choice 3 is entered, following function is called:
int listrented(cars_t cars2)
{
printf("Testing...\n");
}
A simple as a function can be. It's in a separate .c file, maintained in the same project using CodeBlocks. The error that I get is:
error: expected ')' before 'cars2'
Huh? I'm not sure why that's appearing at all. Being able to pass this array of structures to a function would be great, and if anyone could help me out, I would definitely appreciate it.
Cheers.