#include<stdio.h>
#include<string.h>
int main()
{
FILE *f,*e;
char a[100];
int roll;
char key[100];
f=fopen("abc.dat" , "w");
if (f==NULL)
{
printf("\nUnable to Open File....!!!");
return 1;
}
printf("\nEnter any Text to Write in File : ");
gets(a);
fflush(stdin);
printf("\nEnter Roll No. : ");
scanf("%d",&roll);
while(!feof(stdin))
{
fprintf(f,"%s %d\n",a,roll);
printf("\nEnter any Text to Write in File : ");
fflush(stdin);
gets(a);
printf("\nEnter Roll No. : ");
scanf("%d",&roll);
}
fclose(f);
e=fopen("abc.dat" , "r");
if (e==NULL)
{
printf("\nUnable to Open File....!!!!");
return 1;
}
printf("\n\nEnter key : ");
gets(key);
fscanf(e,"%s%d",a,&roll);
while(!feof(e))
{
if (strcmp(key,a)==0)
{
printf("%s %d",a,roll);
}
fscanf(e,"%s%d",a,&roll);
}
fclose(e);
}
#include<string.h>
int main()
{
FILE *f,*e;
char a[100];
int roll;
char key[100];
f=fopen("abc.dat" , "w");
if (f==NULL)
{
printf("\nUnable to Open File....!!!");
return 1;
}
printf("\nEnter any Text to Write in File : ");
gets(a);
fflush(stdin);
printf("\nEnter Roll No. : ");
scanf("%d",&roll);
while(!feof(stdin))
{
fprintf(f,"%s %d\n",a,roll);
printf("\nEnter any Text to Write in File : ");
fflush(stdin);
gets(a);
printf("\nEnter Roll No. : ");
scanf("%d",&roll);
}
fclose(f);
e=fopen("abc.dat" , "r");
if (e==NULL)
{
printf("\nUnable to Open File....!!!!");
return 1;
}
printf("\n\nEnter key : ");
gets(key);
fscanf(e,"%s%d",a,&roll);
while(!feof(e))
{
if (strcmp(key,a)==0)
{
printf("%s %d",a,roll);
}
fscanf(e,"%s%d",a,&roll);
}
fclose(e);
}
No comments:
Post a Comment