how to retrieve data from file?
I filled some entries in following c/c++ file. But I don't know "How to
fetch my uploaded data? , where is data is uploaded ?? and How to perform
searching queries "??? I M week in C..
This file is saved as trial.c in my tc bin.
#include<stdio.h>
#include<string.h>
typedef struct vehicle
{
char name[100];
int lice_no;
int vehicle_type;
char cmpny_name[100];
int menu_year;
}record;
int main(void)
{
int i , choice;
FILE *fp1,*fp2;
char oname[100];
record det;
int recsize;
char c;
fp1 = fopen("record.dat" , "r+");
if(fp1 == NULL)
{
fp1 = fopen("record.dat" , "w+");
if(fp1 == NULL)
{
printf("error in opening file : \n");
return -1;
}
}
recsize = sizeof(det);
fseek(fp1 , 0 ,SEEK_END);
printf("Enter owner Name : ");
scanf("%[^\n]" , det.name);
printf("Enter licence number : ");
scanf("%d" , &det.lice_no);
printf("Enter the vehicle type : ");
scanf("%d" , &det.vehicle_type);
scanf("%c" , &c);
printf("Enter company name : ");
scanf("%[^\n]" , det.cmpny_name);
printf("Enter menufecture year : ");
scanf("%d" , &det.menu_year);
fwrite(&det,recsize,1,fp1);
}
No comments:
Post a Comment