共有回帖数 0 个
-
stdio.h
@函数名称: fopen
函数原型: FILE *fopen(char * filename,char * mode);
函数功能: 以mode指定的方式打开名为filename的文件
函数返回: 成功,返回一个文件指针(文件信息区的起始地址),否则返回0
参数说明: filename-文件名称,mode-打开模式:
r 只读方式打开一个文本文件
rb 只读方式打开一个二进制文件
w 只写方式打开一个文本文件
wb 只写方式打开一个二进制文件
a 追加方式打开一个文本文件
ab 追加方式打开一个二进制文件
r+ 可读可写方式打开一个文本文件
rb+ 可读可写方式打开一个二进制文件
w+ 可读可写方式创建一个文本文件
wb+ 可读可写方式生成一个二进制文件
a+ 可读可写追加方式打开一个文本文件
ab+ 可读可写方式追加一个二进制文件
所属文件: stdio.h
#include stdlib.h
#include stdio.h
#include dir.h
int main()
{
char *s;
char drive[MAXDRIVE];
char dir[MAXDIR];
char file[MAXFILE];
char ext[MAXEXT];
int flags;
s=getenv("COMSPEC");
flags=fnsplit(s,drive,dir,file,ext);
printf("Command processor info:");
if(flags&DRIVE)
printf("tdrive: %s",drive);
if(flags&DIRECTORY)
printf("tdirectory: %s",dir);
if(flags&FILENAME)
printf("tfile: %s",file);
if(flags&EXTENSION)
printf("textension: %s",ext);
return 0;
}
@函数名称: fclose
函数原型: int fclose(FILE * fp);
函数功能: 关闭fp所指的文件,释放文件缓冲区
函数返回: 0-无错,否则非零
参数说明:
所属文件: stdio.h
#include string.h
#include stdio.h
int main()
{
FILE *fp;
char buf[11]="0123456789";
fp=fopen("test.txt","w");
fwrite(&buf,strlen(buf),1,fp);
fclose(fp);
return 0;
}
@函数名称: fflush
函数原型: int fflush(FILE *stream)
函数功能: 清除文件缓冲区,文件以写方式打开时将缓冲区内容写入文件
函数返回: 0-操作成功,非0-操作失败
参数说明: stream-文件指针
所属文件: stdio.h
#include string.h
#include stdio.h
#include conio.h
#include io.h
void flush(FILE *stream);
int main()
{
FILE *stream;
char msg[]="This is a test";
stream=fopen("DUMMY.FIL","w");
fwrite(msg,strlen(msg),1,stream);
clrscr();
printf("Press any key to flush DUMMY.FIL:");
getch();
flush(stream);
printf("File was flushed,Press any key to quit:");
getch();
return 0;
}
void flush(FILE *stream)
{
int duphandle;
fflush(stream);
duphandle=dup(fileno(stream));
close(duphandle);
}
@函数名称: ferror
函数原型: int ferror(FILE *stream)
函数功能: 检测文件操作是否有错误
函数返回: 非0-有错误,0-无错误
参数说明: stream-文件指针
所属文件: stdio.h
#include stdio.h
int main()
{
FILE *stream;
stream=fopen("DUMMY.dat","w");
(void) getc(stream);
if (ferror(stream))
{
printf("Error reading from DUMMY.dat")
clearerr(stream);
}
fclose(stream);
return 0;
}
@函数名称: fileno
函数原型: int fileno(FILE *fp)
函数功能: 得到与fp等价的文件句柄号
函数返回: 文件句柄号
参数说明: fp-由fopen()函数打开的文件指针
所属文件: stdio.h
#include stdio.h
int main()
{
FILE *stream;
stream=fopen("file","r");
printf("File number is %dn",fileno(stream));
fclose(stream);
return 0;
}
@函数名称: freopen
函数原型: FILE *freopen(char *fname,char *mode,FILE *fp)
函数功能: 将一个已打开的fp和一个新的文件名相连接
函数返回: fp值
参数说明: fp-已打开的文件指针
fname-新的文件名称
mode-同函数fopen()中的定义
所属文件: stdio.h
#include stdio.h
int main()
{
if (freopen("OUTPUT.FIL","w",stdout)==NULL)
fprintf(stderr,"error redirecting stdout");
printf("This will go into a file.");
fclose(stdout);
return 0;
}
@函数名称: clearerr
函数原型: void clearerr(FILE * fp);
函数功能: 清除文件指针错误指示器,将文件出错标志清零
函数返回:
参数说明: fp-文件的流指针
所属文件: stdio.h
#include graphics.h
#include stdlib.h
#include stdio.h
#include conio.h
int main()
{
int gdriver=DETECT,gmode,errorcode;
int midx,midy;
initgraph(&gdriver,&gmode,);
errorcode=graphresult();
if (errorcode!=grOk)
{
printf("Graphics error: %s",grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
midx=getmaxx()/2;
midy=getmaxy()/2;
setcolor(getmaxcolor());
settextjustify(CENTER_TEXT,CENTER_TEXT);
outtextxy(midx,midy,"press any key to clear the screen:");
getch();
cleardevice();
outtextxy(midx,midy,"press any key to quit:");
getch();
closegraph();
return 0;
}
@函数名称: fgetc
函数原型: int fgetc(FILE * fp);
函数功能: 从fp所指定的文件中取得下一个字符
函数返回: 返回所得到的字符.若读入出错,返回EOF
参数说明: fp-文件指针
所属文件: stdio.h
#include string.h
#include stdio.h
#include conio.h
int main()
{
FILE *stream;
char string[]="This is a test";
char ch;
stream=fopen("test.txt","w+");
fwrite(string,strlen(string),1,stream);
fseek(stream,0,SEEK_SET);
do
{
ch=fgetc(stream);
putch(ch);
}
while (ch!=EOF);
fclose(stream);
return 0;
}
@函数名称: fgetchar
函数原型: int fgetchar(void)
函数功能: 等价于fgetc(stdin),也等价于getchar,但仅作为函数实现
函数返回: 返回读出的字符,如文件已到结尾,返回值为EOF
参数说明: fp-文件指针
所属文件: stdio.h
#include stdio.h
int main()
{
FILE *fp;
int c;
fp = freopen( "file", "r", stdin );
while( (c = getchar()) != EOF )
putchar©;
fclose( fp );
return 0;
}
@函数名称: fputchar
函数原型: int fputchar(int ch)
函数功能: 在标准输出流(即屏幕上)的当前位置写入一个字符
函数返回: 操作正确时返回写入的字符,错误返回EOF
参数说明: ch-要写入的字符(舍去高位字节)
所属文件: stdio.h
#include stdio.h
int main()
{
char msg[] ="This is a test";
int i=0;
while (msg)
{
fputchar(msg);
i++;
}
return 0;
}
@函数名称: fgets
函数原型: char fgets(char * buf,int n,FILE * fp);
函数功能: 从fp指向的文件中读取一个长度为(n-1)的字符串,存入起始地址为buf的空间
函数返回: 返回地址buf,若遇文件结束或出错,返回NULL
函数说明: buf-存放读入的字符数组指针,n-最大允许的读入字符数,fp-文件指针
所属文件: stdio.h
#include string.h
#include stdio.h
int main()
{
FILE *stream;
char string[]="This is a test";
char msg[20];
stream=fopen("test.txt","w+");
fwrite(string,strlen(string),1,stream);
fseek(stream,0,SEEK_SET);
fgets(msg,strlen(string)+1,stream);
printf("%s",msg);
fclose(stream);
return 0;
}
@函数名称: feof
函数原型: int feof(FILE * fp);
函数功能: 检查文件是否结束.
函数返回: 遇文件结束符返回非零值,否则返回0
参数说明: fp-文件指针
所属文件: stdio.h
#include stdio.h
int main()
{
FILE *stream;
stream=fopen("test.txt","r");
fgetc(stream);
if (feof(stream))
printf("We have reached end-of-file");
fclose(stream);
return 0;
}
函数名称: fputc
函数原型: int fputc(char ch,FILE *fp);
函数功能: 将字符ch输出到fp指向的文件中
函数返回: 成功,则返回该字符;否则返回非0
参数说明: fp-文件指针,ch-要写入的字符(舍去高位字节)
所属文件: stdio.h
#include stdio.h
int main()
{
char msg[]="Hello world";
int i=0;
while (msg)
{
fputc(msg,stdout);
i++;
}
return 0;
}
@函数名称: fputs
函数原型: int fputs(char * str,FILE *fp);
函数功能: 将str指向的字符串输出到fp指向的文件中
函数返回: 成功,则返回0;否则返回非0
参数说明:
所属文件: stdio.h
#include stdio.h
int main()
{
fputs("Hello world",stdout);
return 0;
}
@函数名称: fread
函数原型: int fread(char * pt,unsigned size,unsigned n,FILE * fp);
函数功能: 从fp所指定的文件中读取长度为size的n个数据项,存到pt所指向的内存区
函数返回: 返回所读的数据项个数,如遇文件结束或出错返回0
参数说明: pt-存放读入数据的指针,size-每个数据单位的字节数,n-读入的数据单位个数
所属文件: stdio.h
#include string.h
#include stdio.h
int main()
{
FILE *stream;
char msg[]="this is a test";
char buf[20];
if ((stream=fopen("test.txt","w+"))==NULL)
{
fprintf(stderr,"Cannot open output file.");
return 1;
}
fwrite(msg,strlen(msg)+1,1,stream);
fseek(stream,SEEK_SET,0);
fread(buf,strlen(msg)+1,1,stream);
printf("%s",buf);
fclose(stream);
return 0;
}
@函数名称: fwrite
函数原型: int fwrite(char *ptr,unsigned size,unsigned n,FILE *fp);
函数功能: 把ptr所指向的n*size个字节输出到fp所指向的文件中.
函数返回: 写到fp文件中的数据项个数
参数说明: ptr-存放要写入的数据,size-每个数据单位的字节数,n-读入的数据单位个数
所属文件: stdio.h
#include stdio.h
struct mystruct{
int i;
char ch;
};
int main()
{
FILE *stream;
struct mystruct s;
if ((stream=fopen("TEST.dat","wb"))==NULL)
{
fprintf(stderr,"Cannot open output file.");
return 1;
}
s.i=0;
s.ch='A';
fwrite(&s,sizeof(s),1,stream);
fclose(stream);
return 0;
}
@函数名称: fprintf
函数原型: int fprintf(FILE * fp,char * format,args,...);
函数功能: 把args的值以format指定的格式输出到fp所指定的流式文件中
函数返回: 实际输出的字符数
参数说明: fp-目标文件,format-格式符
所属文件: stdio.h
#include stdio.h
int main()
{
FILE *in,*out;
if ((in=fopen("AUTOEXEC.BAT","rt"))==NULL)
{
fprintf(stderr,"Cannot open input file.");
return 1;
}
if ((out=fopen("AUTOEXEC.BAK","wt"))==NULL)
{
fprintf(stderr,"Cannot open output file.");
return 1;
}
while(!feof(in))
fputc(fgetc(in),out);
fclose(in);
fclose(out);
return 0;
}
@函数名称: fscanf
函数原型: int fscanf(FILE * fp,char format,args,...);
函数功能: 从fp所指定的文件中按format给定的格式将数据输送到args所指向的内存单元
函数返回: 已输入的数据个数
参数说明:
所属文件: stdio.h
#include stdlib.h
#include stdio.h
int main()
{
int i;
printf("Input an integer: ");
if (fscanf(stdin,"%d",&i))
printf("The integer read was: %i",i);
else
{
fprintf(stderr,"Error reading an integer from stdin.");
exit(1);
}
return 0;
}
@函数名称: scanf
函数原型: int scanf(char * format,args,...);
函数功能: 从标准输入设备按format指向的格式字符串规定的格式,输入数据给agrs所指向的单元
函数返回: 读入并赋给args的数据个数.遇文件结束返回EOF,出错返回0
参数说明: args-指针
所属文件: stdio.h
int main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
printf("%d,%d,%dn",a,b,c);
return 0;
}
@函数名称: printf
函数原型: int printf(char * format,args,...);
函数功能: 按format指向的格式字符串所规定的格式,将输出表列args的值输出到标准输出设备
函数返回: 输出字符的个数.若出错返回负数
参数说明: format-是一个字串,或字符数组的起始地址
所属文件: stdio.h
#include stdio.h
int main()
{
char c='a';
int i=97;
printf("%c,%dn",c,c);
printf("%c,%dn",i,i);
return 0;
}
@函数名称: fseek
函数原型: int fseek(FILE * fp,long offset,int base);
函数功能: 将fp所指文件的位置指针移到以base所指位置为基准,以offset为位移量的位置
函数返回: 返回当前位置,否则返回-1
参数说明: fp-文件指针
offset-相对于origin规定的偏移位置量
origin-指针移动的起始位置,可设置为以下三种情况:
SEEK_SET 文件开始位置 0
SEEK_CUR 文件当前位置 1
SEEK_END 文件结束位置 2
所属文件: stdio.h
#include stdio.h
long filesize(FILE *stream);
int main()
{
FILE *stream;
stream=fopen("MYFILE.TXT","w+");
fprintf(stream,"This is a test");
printf("Filesize of MYFILE.TXT is %ld bytes",filesize(stream));
fclose(stream);
return 0;
}
long filesize(FILE *stream)
{
long curpos,length;
curpos=ftell(stream);
fseek(stream,0L,SEEK_END);
length=ftell(stream);
fseek(stream,curpos,SEEK_SET);
return length;
}
@函数名称: ftell
函数原型: long ftell(FILE * fp);
函数功能: 得到文件位置指示器的数值
函数返回: fp指向的文件中的读写位置
参数说明:
所属文件: stdio.h
#include stdio.h
int main()
{
FILE *stream;
stream=fopen("MYFILE.TXT","w+");
fprintf(stream,"This is a test");
printf("The file pointer is at byte %ld",ftell(stream));
fclose(stream);
return 0;
}
@函数名称: getc
函数原型: int getc(FILE *fp);
函数功能: 从fp所指向的文件中读入一个字符
函数返回: 返回所读的字符,若文件结束或出错,返回EOF
参数说明:
所属文件: stdio.h
#include stdio.h
int main()
{
char ch;
printf("Input a character:");
ch=getc(stdin);
printf("The character input was: '%c'",ch);
return 0;
}
@函数名称: getchar
函数原型: int getchar(void);
函数功能: 从标准输入设备读取一个字符
函数返回: 所读字符.若文件结束或出错,则返回-1
参数说明:
所属文件: stdio.h
#includestdio.h
int main()
{
char c;
c=getchar();
putchar©;
return 0;
}
@函数名称: getche
函数原型: int getche(void)
函数功能: 从控制台读取一个字符并回显
函数返回: 读取的字符
参数说明:
所属文件: stdio.h
#include stdio.h
#include conio.h
int main()
{
char ch;
printf("Input a character:");
ch=getche();
printf("You input a '%c'",ch);
return 0;
}
@函数名称: getw
函数原型: int getw(FILE * fp);
函数功能: 从fp所指向的文件读取一个字(整数)
函数返回: 输入的整数.如果文件结束或出错,返回-1
参数说明:
所属文件: stdio.h
#include stdio.h
#include stdlib.h
#define FNAME "test.dat"
int main()
{
FILE *fp;
int word;
fp=fopen(FNAME,"wb");
if (fp==NULL)
{
printf("Error opening file %s",FNAME);
exit(1);
}
word=94;
putw(word,fp);
if (ferror(fp))
printf("Error writing to file!");
else
printf("Successful write!");
fclose(fp);
fp=fopen(FNAME,"rb");
if (fp==NULL)
{
printf("Error opening file %s",FNAME);
exit(1);
}
word=getw(fp);
if (ferror(fp))
printf("Error reading file!");
else
printf("Successful read: word=%d",word);
fclose(fp);
unlink(FNAME);
return 0;
}
@函数名称: putc
函数原型: int putc(int ch,FILE * fp);
函数功能: 把一个字符ch输出到fp所指定的文件中
函数返回: 输出字符ch,若出错,返回EOF
参数说明:
所属文件: stdio.h
#include stdio.h
int main()
{
char msg[]="Hello world";
int i=0;
while (msg)
putc(msg[i++],stdout);
return 0;
}
@函数名称: putchar
函数原型: int putchar(char ch);
函数功能: 把字符ch输出到标准输出设备
函数返回: 输出字符ch,若出错,返回EOF
参数说明:
所属文件: stdio.h
#includestdio.h
int main()
{
char a,b,c;
a='B';
b='O';
c='Y';
putchar(a);putchar(b);putchar©;
return 0;
}
@函数名称: puts
函数原型: int puts(char * str);
函数功能: 把str指向的字符串输出到标准输出设备,将' '转换为回车换行
函数返回: 返回换行符,若失败,返回EOF
参数说明:
所属文件: stdio.h
#include stdio.h
int main()
{
char string[]="This is an example output string";
puts(string);
return 0;
}
@函数名称: gets
函数原型: char * gets(char *str)
函数功能: 从终端输入一个字符串到字符数组,并且得到一个函数值.该函数值是字符数组的起始地址
函数返回: 读取的字符指针str,操作错误返回NULL
参数说明: str-保存读取的字符串
所属文件: stdio.h
#include stdio.h
int main()
{
char buffer[80];
while(gets(buffer)!=NULL)
puts(buffer);
return 0;
}
@函数名称: putw
函数原型: int putw(int w,FILE * fp);
函数功能: 将一个整数w(即一个字)写到fp指向的文件中
函数返回: 返回输出的整数,若出错,返回EOF
参数说明:
所属文件: stdio.h
#include stdio.h
#include stdlib.h
#define FNAME "test.dat"
int main()
{
FILE *fp;
int word;
fp=fopen(FNAME,"wb");
if (fp==NULL)
{
printf("Error opening file %s",FNAME);
exit(1);
}
word=94;
putw(word,fp);
if (ferror(fp))
printf("Error writing to file");
else
printf("Successful write");
fclose(fp);
fp=fopen(FNAME,"rb");
if (fp==NULL)
{
printf("Error opening file %s",FNAME);
exit(1);
}
word=getw(fp);
if (ferror(fp))
printf("Error reading file");
else
printf("Successful read: word=%d",word);
fclose(fp);
unlink(FNAME);
return 0;
}
@函数名称: rename
函数原型: int rename(char * oldname,char * newname);
函数功能: 把由oldname所指的文件名,改为由newname所指的文件名
函数返回: 成功返回0,出错反回-1
参数说明:
所属文件: stdio.h
#include stdio.h
int main()
{
char oldname[80],newname[80];
printf("File to rename: ");
gets(oldname);
printf("New name: ");
gets(newname);
if (rename(oldname,newname)==0)
printf("Renamed %s to %s.",oldname,newname);
else
perror("rename");
return 0;
}
@函数名称: remove
函数原型: int remove(char *fname)
函数功能: 删除一个文件
函数返回: 0:操作成功,-1:操作失败
参数说明: fname-要删除的文件名称
所属文件: stdio.h
#include stdio.h
int main()
{
char file[80];
printf("File to delete: ");
gets(file);
if(remove(file)==0)
printf("Removed %s.",file);
else
perror("remove");
return 0;
}
@函数名称: rewind
函数原型: void rewind(FILE * fp);
函数功能: 将fp指示的文件中的位置指针置于文件头位置,并清除文件结束标志和错识标志
函数返回:
参数说明:
所属文件: stdio.h
#include stdio.h
#include dir.h
int main()
{
FILE *fp;
char *fname ="Test.dat",*newname,first;
newname=mktemp(fname);
fp=fopen(newname,"w+");
fprintf(fp,"abcdefghijklmnopqrstuvwxyz");
rewind(fp);
fscanf(fp,"%c",&first);
printf("The first character is: %c",first);
fclose(fp);
remove(newname);
return 0;
}
@函数名称: perror
函数原型: void perror(const char *s)
函数功能: 将表示错误的全程变量errno所对应解释输出到流stderr中
函数返回:
参数说明: s-表示错误的附加信息字符串
所属文件: stdio.h
#include stdio.h
int main()
{
FILE *fp;
fp=fopen("perror.dat","r");
if (!fp)
perror("Unable to open file for reading");
return 0;
}
@函数名称: setbuf
函数原型: void setbuf(FILE *stream,char *buf)
函数功能: 指定某个流文件操作所使用的缓冲区
函数返回:
参数说明: fp-使用fopen打开的文件流指针,buf-大小必须为BUFSIZ宏长度的内存指针
所属文件: stdio.h
#include stdio.h
char outbuf[BUFSIZ];
int main()
{
setbuf(stdout,outbuf);
puts("This is a test of buffered output.");
puts("This output will go into outbuf,");
puts("and won't appear until the buffer,");
puts("fills up or we flush the stream.");
fflush(stdout);
return 0;
}
@函数名称: setvbuf
函数原型: int setvbuf(FILE *fp,char *buf,int type,size_t size)
函数功能: 对指定文件fp指定操作缓冲区
函数返回: 0-操作成功,非0-操作失败
参数说明: fp-文件指针,buf-缓冲区指针,size-缓冲区大小 ,type-模式,取值含义如下:
_IOFBF 0 满缓冲区后刷新缓冲区
_IOLBF 1 在缓冲区写入或读出一行字符后刷新缓冲区
_IONBF 2 满不缓冲
所属文件: stdio.h
#include stdio.h
int main()
{
FILE *input,*output;
char bufr[512];
input=fopen("file.in","rb");
output=fopen("file.out","w");
if (setvbuf(input,bufr,_IOFBF,512)!=0)
printf("failed to set up buffer for input file");
else
printf("buffer set up for input file");
if (setvbuf(output,NULL,_IOLBF,132)!=0)
printf("failed to set up buffer for output file");
else
printf("buffer set up for output file");
fclose(input);
fclose(output);
return 0;
}
@函数名称: sprintf
函数原型: int sprintf (char *buffer,const char *format,… )
函数功能: buffer写入的缓冲区
函数返回: 写入的字符数(不包括终止符)
参数说明:
所属文件: stdio.h
#include stdio.h
#include math.h
int main()
{
char buffer[80];
sprintf(buffer,"An approximation of Pi is %f",M_PI);
puts(buffer);
return 0;
}
@函数名称: sscanf
函数原型: int sscanf(const char *in_str,const char *format,… )
函数功能: 从缓冲区中按指定格式输入字符,该函数用法同scanf
函数返回:
参数说明: in_str-数据源缓冲区
所属文件: stdio.h
#include stdio.h
int main()
{
int day,year;
char weekday[10],month[10];
sscanf("Friday August 0014 1987","%s %s %d %d",weekday,month,&day,&year);
printf("%s %s %d %dn",weekday,month,day,year);
return 0;
}
@函数名称: tmpfile
函数原型: FILE *tmpfile(void)
函数功能: 自动产生一个临时文件,并返回其流指针
函数返回: 临时文件流指针
参数说明:
所属文件: stdio.h
#include stdio.h
#include process.h
int main()
{
FILE *tempfp;
tempfp=tmpfile();
if (tempfp)
printf("Temporary file created");
else
{
printf("Unable to create temporary file");
exit(1);
}
return 0;
}
@函数名称: tmpnam
函数原型: char *tmpnam(char *s)
函数功能: 自动产生唯一的文件名称
函数返回:
参数说明: s-用于存放临时文件的字符指针
所属文件: stdio.h
#include stdio.h
int main()
{
char name[13];
tmpnam(name);
printf("Temporary name: %s",name);
return 0;
}
@函数名称: ungetc
函数原型: int ungetc(int c,FILE *fp)
函数功能: 将字符c放到文件流fp的首部
函数返回: 字符c-操作成功,EOF-操作失败
参数说明: c-要写入的字符,fp-文件流指针
所属文件: stdio.h
#include stdio.h
#include ctype.h
int main()
{
int i=0;
char ch;
puts("Input an integer followed by a char:");
while((ch=getchar())!=EOF && isdigit(ch))
i=10*i+ch-48;
if (ch!=EOF)
ungetc(ch,stdin);
printf("i=%d,next char in buffer=%c",i,getchar());
return 0;
}
@函数名称: ungetch
函数原型: int ungetch(int c)
函数功能: 把一个字符退回到键盘缓冲区中
函数返回:
参数说明:
所属文件: stdio.h
#include stdio.h
#include ctype.h
#include conio.h
int main()
{
int i=0;
char ch;
puts("Input an integer followed by a char:");
while((ch=getche())!=EOF&&isdigit(ch))
i=10*i+ch-48;
if(ch!=EOF)
ungetch(ch);
printf("i=%d,next char in buffer=%c",i,getch());
return 0;
}
@函数名称: fgetpos,fsetpos
函数原型: int fgetpos(FILE *fp,fpos_t *pos);
int fsetpos(FILE *stream,const fpos_t *pos);
函数功能: 获取、设置文件位置
函数返回: 如果操作成功,数返回零值,否则返回一个非零值
参数说明: fp-文件指针,pos-对象指针
所属文件: stdio.h
#include stdio.h
int main()
{
FILE *fp;
fpos_t position;
auto char buffer[80];
fp=fopen("file","r");
if(fp!=NULL){
fgetpos(fp,&position); /* get position */
fgets(buffer,80,fp); /* read record */
fsetpos(fp,&position); /* set position */
fgets(buffer,80,fp); /* read same record */
fclose(fp);
}
return 0;
}
楼主 2016-02-12 14:44 回复
Copyright © 2010~2015 直线网 版权所有,All Rights Reserved.沪ICP备10039589号
意见反馈 |
关于直线 |
版权声明 |
会员须知