+ 1

Help me in this file handling

Read the folowing... #include<stdio.h> #include<stdlib.h> #include<conio.h> int main() {char c,filename[10]; FILE *f1,*f2; int n; int temp=1;long offset; printf("enter filename:\n"); scanf("%s",filename); printf("enter offset value:\n"); scanf("%ld",&offset); f1=fopen(filename,"w"); printf("enter text in f1:\n"); while((c=getchar())!=-1) putc(c,f1); n=ftell(f1); printf("n=%d\n",n); fclose(f1); f1=fopen(filename,"r"); f2=fopen("text","w"); if(offset>0&&offset<n) fseek(f1,offset,0); else if(offset<0) fseek(f1,offset,2); while((c=getc(f1))!=-1) putc(c,f2); fclose(f2); f2=fopen("text","r"); while((c=getc(f2))!=-1) printf("%c",c); fclose(f2); } // Why the program is setting the offset value 2 less than what is being provided

7th Apr 2019, 6:51 PM
Dibas Behera
Dibas Behera - avatar
1 Answer
+ 3
please write this on code play ground and link it here
9th Apr 2019, 8:12 PM
āœ³AsterisKāœ³
āœ³AsterisKāœ³ - avatar