1 Replies - 3164 Views - Last Post: 04 December 2008 - 02:54 AM Rate Topic: -----

#1 shangyi  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 28
  • Joined: 15-June 08

typedef array stuctures to pass into user defined function

Post icon  Posted 04 December 2008 - 02:24 AM

Hi guys im facing this problem:

#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <stdlib.h>

typedef struct{
	int FlightID;
	char Destination[10];
	char date[11];
	char time[5];
	int seatNo;
}flightInfo;


int flightChecking(flightInfo *FlightRec[]);

int main()
{
	int flightid;
	flightInfo flightRec[2];

flightid= flightChecking(&flightRec);

	return 0;
}
int flightChecking(flightInfo *FlightRec[])
{
	int i;
	FILE *getFlight;
	getFlight = fopen("Flight.txt", "r");

	for(i=0;i<2;i++){
		while((fscanf(getFlight, "%d ", &(*FlightRec[i]).FlightID))!=EOF)
		{
			fscanf(getFlight, "%d ", &(*FlightRec[i]).FlightID);
			fscanf(getFlight, "%s ", (*FlightRec[i]).Destination);
			fscanf(getFlight, "%s ", (*FlightRec[i]).date);
			fscanf(getFlight, "%s", (*FlightRec[i]).time);
			fscanf(getFlight, "%d", &(*FlightRec[i]).seatNo);
			break;
		}
	}


	return 0;
}



However, i get the following warning messages:
warning C4047: 'function' : 'flightInfo **' differs in levels of indirection from 'flightInfo (*)[2]'
warning C4024: 'flightChecking' : different types for formal and actual parameter 1.

I cant get the user defined function to accept a structure array =( Can anyone help me please?

You help is greatly appreciated.
Thanks in advance

This post has been edited by shangyi: 04 December 2008 - 02:28 AM


Is This A Good Question/Topic? 0
  • +

Replies To: typedef array stuctures to pass into user defined function

#2 shangyi  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 28
  • Joined: 15-June 08

Re: typedef array stuctures to pass into user defined function

Posted 04 December 2008 - 02:54 AM

EDIT: i have found the problem in my code! i completely forgot that if i pass a complete array into a function the values will change automatically! so there is no need for me to put a pointer to an address of the structure.

My bad! just in case anyone does not understand my fixed code is :

#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <stdlib.h>

typedef struct{
	 int FlightID;
	 char Destination[10];
	 char date[11];
	 char time[5];
	 int seatNo;
}flightInfo;


int flightChecking(flightInfo FlightRec[]);

int main()
{
	 int flightid;
	 flightInfo flightRec[2];

flightid= flightChecking(flightRec);

	 return 0;
}
int flightChecking(flightInfo FlightRec[])
{
	 int i;
	 FILE *getFlight;
	 getFlight = fopen("Flight.txt", "r");

	 for(i=0;i<2;i++){
		  while((fscanf(getFlight, "%d ", &FlightRec[i].FlightID))!=EOF)
		  {
			   fscanf(getFlight, "%d ", &FlightRec[i].FlightID);
			   fscanf(getFlight, "%s ", FlightRec[i].Destination);
			   fscanf(getFlight, "%s ", FlightRec[i].date);
			   fscanf(getFlight, "%s", FlightRec[i].time);
			   fscanf(getFlight, "%d", &FlightRec[i].seatNo);
			   break;
		  }
	 }


	 return 0;
}


This post has been edited by shangyi: 04 December 2008 - 02:56 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1