fgetpos

来源:互联网 发布:第一个编程语言 编辑:程序博客网 时间:2024/06/05 18:34



fgetpos是一个函数名,功能是依据当前文件的句柄,获取当前访问指针位置信息。
中文名
fgetpos
名词类型
函数
名词领域
编程
功    能
获取当前访问指针位置信息

 

目录

  1. 1函数名
  2. 2程序事例
  3. 程序例1
  4. 程序例2

函数名

编辑
函数原型: int fgetpos(FILE * restrict stream,fpos_t * restrict pos);
函数功能:在pos所指的位置放置一个fpos_t值,这个值描述了文件中的一个位置。
返回值:如果成功,函数返回0;否则返回一个非零值。

程序事例

编辑

程序例1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<string.h>
#include<stdio.h>
intmain(void)
{
FILE*stream;
charstring[]="Thisisatest";
fpos_t filepos;
/*openafileforupdate*/
stream=fopen("DUMMY.FIL","w+");
/*writeastringintothefile*/
fwrite(string,strlen(string),1,stream);
/*reportthefilepointerposition*/
fgetpos(stream,&filepos);
printf("Thefilepointerisatbyte\
%ld\n",filepos);
fclose(stream);
return0;
}

程序例2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
voidDeleteRowData(intRowNum)
{/*typedef__int64fpos_t1;*/
typedef fpos_t;
FILE*fin;
charstrsub[20];/**strsub没显示*/
fpos_t pos_w;
fpos_t pos_r;
fpos_t pos;
inti,k,L=1;
char*one_line;
L=RowNum;
*strsub=0;
one_line=(char*)malloc(1000*sizeof(char));
fin=fopen("data.TXT","rb+");
for(i=1;i<L;i++)fgets(one_line,999,fin);
fgetpos(fin,&pos_w);/*该函数在casiodt930上行不通,不解*/
fgets(one_line,999,fin);
fgetpos(fin,&pos_r);
pos=pos_r;
while(1==1)
{
fsetpos(fin,&pos);
if(fgets(one_line,999,fin)==NULL)break;
fgetpos(fin,&pos_r);
pos=pos_w;
fsetpos(fin,&pos);
fprintf(fin,"%s",one_line);
fgetpos(fin,&pos_w);
pos=pos_r;
}
fclose(fin);
//sprintf(strsub,"%s,%d","test3",L);
//Display(7,10,(UB*)"",0);/*清空*/
//Display(7,10,(UB*)strsub,0);
return;
0 0
原创粉丝点击