//C code for Text file creatation and searching.
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
FILE *p;
int regno,mark,n,i,f=0;
char name[10],rname[10];
printf("Enter the number of students:");
scanf("%d",&n);
p=fopen("mu.txt","w");
printf("Enter thename regno,mark of students:");
for(i=0;i<n;i++)
{
scanf("%s%d%d",name,®no,&mark);
fprintf(p,"%s %d %d",name,regno,mark);
}
fclose(p);
printf("enter the searching name:");
scanf("%s",rname);
p=fopen("mu.txt","r");
do
{
fscanf(p,"%s%d%d",name,®no,&mark);
if(strcmp(name,rname)==0)
{
printf("%s %d %d",name,regno,mark);
f=1;
break;
}
}
while(!feof(p));
if(f==0)
printf("The given name is not present");
fclose(p);
getch();
}
No comments:
Post a Comment