#include #define max 10 main() { int fp,i,no,s,ch=0; char buf[max]; system("clear"); printf("\n Enter the no. of records:"); scanf("%d",&no); fp=creat("kvr.txt"); for(i=0;i { printf("\n Enter string for Record %d :",i+1); scanf("%s",&buf); s=write(fp,buf,max); printf("\n Written to file -no.of bytes written=%d\n",s); } close(fp); fp=open("kvr.txt"); while(ch!=-1) { printf("\n \n To view the content file"); printf("\n 0.View entire contents"); printf("\n no.for a particular record"); printf("\n-1.Exit\n"); scanf("%d",&ch); printf("\n---------------------------------------------"); if(ch==0) for(i=0;i { read(fp,buf,max); printf("\n %d %s",i+1,buf); } else if((ch>0)&&(ch<=no)) { lseek(fp,SEEK_SET,(ch-1)*max); read(fp,&buf,max); printf("\n %d%a",ch,buf); } } close(fp); }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|