91学习

陪伴你每一天!

fseek()定位文件来获取部分内容

#include <stdio.h>

#include <process.h>


void main(){

FILE *fp;

char filename[30],str[50];

printf("please input the filename:\n");

scanf("%s",filename);

if((fp=fopen(filename,"wb"))==NULL){

printf("can not open file:\npress any key to coun tinue:\n");

getchar();

exit(0);

}

printf("please input the string:\n");

getchar();

gets(str);

fputs(str,fp);

fclose(fp);

if((fp=fopen(filename,"rb"))==NULL){

printf("can not open file:\npress any key to continue:\n");

getchar();

exit(0);

}

fseek(fp,4L,0);

fgets(str,sizeof(str),fp);

putchar('\n');

puts(str);

fclose(fp);

}

加威信18790284560免费送POS机.jpg

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。