#include <stdio.h>
#include <stdlib.h>
void readBytes(FILE*fp,int offset,int num,char str2[100]);
int main(int argc, char *argv[]) {
FILE*fp=fopen("file.txt","w+");
if(fp==NULL){
printf("error\n");
exit(0);
}
char str[100],str2[100];
int offset,num;
//input
printf("please input the sentences you want to write to the file\n");
gets(str);
fprintf(fp,"%s",str);
printf("please enter the offset of the first character to be read\n");
scanf("%d",&offset);
printf("please enter the number of characters to be read\n");
scanf("%d",&num);
//call the function
readBytes(fp,offset,num,str2);
fclose(fp);
system ("pause");
return 0;
}
void readBytes(FILE*fp,int offset,int num,char str2[100]){
fseek(fp,offset,SEEK_SET);
fgets(str2,num+1,fp);
printf("result: ");
puts(str2);
}