Wednesday, 23 April 2014

32. Write a program that will input a person’s first name, last name, SSN number and age and write the information to a data file. One person’s information should be in a single line. Use the function fprintfto write to the data file. Accept the information and write the data within a loop. Your program should exit the loop when the word ’EXIT’ is entered for the first name. Remember to close the file before terminating the program. Hint: Use the function strcmpO to compare two strings.



#include <stdio.h>
#include<string.h>
#include<conio.h> main()
{
char fname[50], lname[50]; int ssn, age;
FILE *fp; clrscr();
if ( (fp = fopen("vim","w")) == NULL)
{
fprintf(stderr, "Cannot open input file.\n"); getch();
return 1;
}
do
{ printf("enter the First name:"); scanf("%s",fname); if(strcmp(fname,"EXIT")==0)
{
fclose(fp); exit(1);
}
printf("enter the Last name:"); scanf("%s",lname); printf("enter the SSN:"); scanf("%d",&ssn); printf("enter the age:"); scanf("%d",&age);
fprintf(fp,"%s %s %d %d\n",fname,lname,ssn,age);
} while (1);
}

1 comment:

  1. Slot machines in Las Vegas, NV - MapyRO
    Las Vegas Slot 영주 출장마사지 Machines and Machines - Las Vegas, NV. All-Time Highest Payouts. Play Now. Slot 강릉 출장마사지 machines in Las Vegas, NV. Free Slots 동두천 출장마사지 games 남양주 출장마사지 and 군포 출장마사지 slots machines.

    ReplyDelete