TRIP* ReadTravel(int* pnum_trips)
{
TRIP* tr = NULL;//initiallization for realloc
char stop = '0';
while (stop != STOP_INSERTING_TRIPS)
{
tr = (TRIP*)realloc(tr, (1+ *pnum_trips) * sizeof(TRIP));
tr[*pnum_trips] = ReadTrip();
(*pnum_trips)++;
printf("If you want to stop adding trips, type '%c'\n", STOP_INSERTING_TRIPS);
printf("if you want to continue adding trips, type any other key\n");
scanf(" %c", &stop);
}
return tr;
}
void main()
{
TRIP* trav;
int num_trips = 0;
int i;
trav = ReadTravel(num_trips);
PrintTravel(trav, num_trips);
}
TRIP ReadTrip()
{
TRIP tr;
printf("Enter the city you START your trip in: ");
scanf("%s", tr.starting_city);
printf("Enter the city you END your trip in: ");
scanf("%s", tr.destination_city);
printf("Enter the starting date of the trip:\n");
tr.trip_start = ReadDate();
printf("Enter the arrival date of the trip:\n");
tr.arrival_date = ReadDate();
printf("Enter the price of the trip: ");
scanf("%lf", &tr.trip_price);
return tr;
}
TRIP is a struct in the code, let's say it works because it's not the reason i'm here. in the line with the "realloc" there seems to be a problem but i don't understand what. when i delete the "*pnum_trips" it seems to work okay, but i don't understand what is the problem with "*pnum_trips". help please Edit: i added main() and ReadTrip()