Saving and writing to a file

My program doesn't seem to be saving my information to the file

Page 1 of 1

1 Replies - 563 Views - Last Post: 16 April 2009 - 02:41 PM Rate Topic: -----

#1 cal_vincy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-April 09

Saving and writing to a file

Posted 16 April 2009 - 01:52 PM

#include <stdio.h>              /* writing to a ramdom access file */       

struct passengerData 
{
	/* passengerData structure definition */
	int passportnum;		    /* passport number */
	char seatnum [6];			/* seat number */
	char flightnum [10];		/* flight number */
	char gatenum [6];			/* gate number */
	char firstn [15];			/* first name */
	char lastn [10];			/* last name */
	char date [10];				/* travel date */
	char time [6];				/* departure time */
	char destination [20];		/* destination */
};                              /* end structure passengerData */


int main()
	{

			printf("\n********************************************");
			printf("\n*                                          *\n");
			printf("* Welcome to LITA AIR Self Check-In System *\n");
			printf("*                                          *\n");
			printf("********************************************\n");
			printf("\n\n");

	FILE *cfPtr;	// passenger.dat file pointer
	FILE *gfPtr;	// passenger.dat file pointer

	// creat a passengerData with default information 
	struct passengerData passenger = {0, "miss", "miss", "miss", "missing", "missing", "miss", "miss", "missing"};

	// fopen the file; exits if file cannot be open 
	if ( (cfPtr = fopen("passenger.dat", "rb+" )) == NULL )
		{
			printf ( " File could not be opened\n" );
		} // end if 

	else 
		{
			// write user specified information to a file */
			fwrite( &passenger, sizeof( struct passengerData ), 1, cfPtr );
			
			// require user to specify number */
			printf( "Enter your passport or E-ticket number\n" );		
			scanf( "%d", &passenger.passportnum);

/*
			if(passenger.passportnum != 25641)
			{
				for(int c=0; c<3; c++)
				{
					printf("Invalid Passport Number");
					printf( "Enter your passport or E-ticket number\n" );		
					scanf( "%d", &passenger.passportnum);
				}
				return -1;	
			}
*/
return 0;	/* successful termination */	
					
					
	} /* end main */


*** MOD EDIT: Added code tags. Please :code: ***

This post has been edited by JackOfAllTrades: 16 April 2009 - 04:11 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Saving and writing to a file

#2 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 485
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: Saving and writing to a file

Posted 16 April 2009 - 02:41 PM

Do you have a specific problem or question?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1