Thursday, 20 March 2014

PROGRAM IN C TO CREATE A SEQUENTIAL FILE

/*………Hey guy’s this is a program to Create a sequential file………… */
#include <stdio.h>
/*…Main Function Start’s….*/
void main()
{
/*…Initialization and Declaration..*/
int account;
char name[ 30 ];
double balance;
FILE *cfPtr;                                                             /* cfPtr = clients.dat file pointer */
/*…Condition Checking…*/
if ( ( cfPtr = fopen( “clients.dat”, “w” ) ) == NULL )
printf( “File could not be opened\n” );
else { 
printf( “Enter the account, name, and balance.\n” );
printf( “Enter EOF to end input.\n” );
printf( “? ” );
scanf( “%d%s%lf”, &account, name, &balance );
while ( !feof( stdin ) )

fprintf( cfPtr, “%d %s %.2f\n”, 
account, name, balance );
printf( “? ” );
scanf( “%d%s%lf”, &account, name, &balance );
}
fclose( cfPtr );                /*…Close The File..*/
}
getch();
}
/*….Main Function End’s…*/

/*..The output is…:::::::


Image
 

No comments:

Post a Comment