c语言fgetc为啥有的用fputc,fgetc而有的用fputchar,fgetchar。到底现在用哪个?

12406人阅读
c语言积累(3)
& & &由于最近经常使用到c语言中的读写文件,所以在此总结以下,方便以后查找.
& & 在c中,文件操作都是由库函数来实现的,主要是分为读和写两种操作,以下详细讲解以下所有有关文件操作的邯郸乎的用法:
(1)fopen()函数:打开文
包含头文件:#include&stdio.h&
格式:FILE * fopen(const char * path,const char * mode);
&path:需要打开的文件路径
& mode:文件打开方式
以只读方式打开文件,该文件必须存在。
以可读写方式打开文件,该文件必须存在。
读写打开一个二进制文件,允许读数据。
读写打开一个文本文件,允许读和写。
打开只写文件,若文件存在则文件长度清为0,即该文件内容会消失。若文件不存在则建立该文件。
打开可读写文件,若文件存在则文件长度清为零,即该文件内容会消失。若文件不存在则建立该文件。
以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。(EOF符保留)
以附加方式打开可读写的文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾后,即文件原先的内容会被保留。 (原来的EOF符不保留)
只写打开或新建一个二进制文件;只允许写数据。
读写打开或建立一个二进制文件,允许读和写。
读写打开或着建立一个文本文件;允许读写。
读写打开一个文本文件,允许读或在文本末追加数据。
读写打开一个二进制文件,允许读或在文件末追加数据。
现在对上面的文件打开方式做个总结:
文件使用方式由r,w,a,t,b,+六个字符拼成,各字符的含义是:
&&& r(read): 读
&&& w(write): 写
&&& a(append): 追加
&&& t(text): 文本文件,可省略不写
&&& b(banary): 二进制文件
&&& +: 读和写
返回值
&&&&如果文件顺利打开,返回指向该流的文件指针。如果文件打开失败则返回NULL,并把错误代码存在errno中。
&&&&一般而言,打开文件后会作一些文件读取或写入的动作,若打开文件失败,接下来的读写动作也无法顺利进行,所以一般在fopen()后作错误判断及处理。
(2)fread()函数和fwrite()函数:(可以用来实现对数据块的操作)
1.一般调用形式
& fread(buffer,size,count,fp);
& fwrite(buffer,size,count,fp);
& (1)buffer:是一个指针,对fread来说,它是读入数据的存放地址。对fwrite来说,是要输出数据的地址。
& (2)size:要读写的字节数;
& (3)count:要进行读写多少个size字节的数据项;
& (4)fp:文件型指针。
C语言还提供了用于整块数据的读写函数。 可用来读写一组数据,如一个数组元素,一个结构变量的值等。读数据块函数调用的一般形式为: fread(buffer,size,count,fp); 写数据块函数调用的一般形式为: fwrite(buffer,size,count,fp); 其中buffer是一个指针,在fread函数中,它表示存放输入数据的首地址。在fwrite函数中,它表示存放输出数据的首地址。
size 表示数据块的字节数。count 表示要读写的数据块块数。fp 表示文件指针。
例如:fread(fa,4,5,fp); 其意义是从fp所指的文件中,每次读4个字节(一个实数)送入实数组fa中,连续读5次,即读5个实数到fa中。
(3)fgetc()和fputc():字符读写函数
fgetc函数(getc函数)
&(1)一般调用形式
& & & & ch=fgetc(fp);
& & & & 从指定的文件读入一个字符,即从fp所指向的文件中读入一个字符赋给ch。
(3)返回值
& & & & 成功:返回值所得到的字符;
& & & & 失败:返回EOF(-1)。
fputc函数():
(1)一般调用形式
&fputc(ch,fp);
把一个字符写到磁盘文件上去,即将字符ch输出到fp所指向的文件中去。
(3)返回值
成功:返回值就是输出的字符;
失败:返回EOF(-1)。
说明:函数putchar()是在stdio.h中用预处理命令定义的宏,即:
#define putchar(c) & & fputc(c,stdout)
4、fgets()和fputs()函数:读写字符串函数
(1)fgets():char *fgets(char
*str, int num, FILE *fp)&
参数说明:str: 保存从文件读取出来的字符串&&&&&&&
& & & & &fp: 待读文件的文件指针
& & & & &num: 表示从文件中读出的字符串不超过 n-1个字符。在读入的最后一个字符后加上串结束标志'\0'
(2)fputs(char * s,FILE * stream);
5、fscanf()和fprintf()函数:格式化读写函数
(1)fprintf()函数:输出格式化字符串到流或者是将格式化后的字符串写到输出流(文件)
原型:int fprintf( FILE
*stream, const char *format [, argument ]…);&
例子:fprintf(fp, &%s %s %d %f&, str1,str2, a, b) ;
(2)fscanf()函数:输出文件中的内容到某个变量中。
int fscanf(FILE *stream, char *format,[argument...]);
  int fscanf(文件指针,格式字符串,输入列表);
  for example:
  FILE *
  char a[];
  fscanf(fp,&%s%d%lf&,a,&b,&c)
  返回值:整型,数值等于[argument...]的个数
6、ftell()函数:得到流式文件的当前读写位置,其返回值是当前读写位置偏离文件头部的字节数。
原型:long ftell(FILE *fp)
7、&fseek()函数:把fp的文件读写位置指针移到指定的位置。
int fseek(FILE *fp,long offset,int origin);
origin指的是“起始点”,它有三个常量的值,如下:
起始点对应的数字&& 代表的文件位置
SEEK_SET&0&& 文件开头
SEEK_CUR&1&& 文件当前位置
SEEK_END&2&& 文件末尾
8、&rewind()函数:将文件指针重新指向一个流的开头
原型:int rewind(FILE *stream);&
例子:一般我们会通过下面的方法来获取文件中字符的个数:
&&& FILE *fs=fopen(&C:\1.txt&,&r&);//创建文件流
&&& long length=0;//声明文件长度
&&& fseek(fs,0,SEEK_END);//将文件内部指针放到文件最后面
&&& length=ftell(fs);//读取文件指针的位置,得到文件字符的个数
&&& rewind(fs);//将文件指针重置到文件最前面
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:349141次
积分:2869
积分:2869
排名:第8575名
原创:43篇
转载:15篇
评论:24条
(1)(2)(2)(1)(1)(11)(4)(3)(25)(8)12407人阅读
c语言积累(3)
& & &由于最近经常使用到c语言中的读写文件,所以在此总结以下,方便以后查找.
& & 在c中,文件操作都是由库函数来实现的,主要是分为读和写两种操作,以下详细讲解以下所有有关文件操作的邯郸乎的用法:
(1)fopen()函数:打开文
包含头文件:#include&stdio.h&
格式:FILE * fopen(const char * path,const char * mode);
&path:需要打开的文件路径
& mode:文件打开方式
以只读方式打开文件,该文件必须存在。
以可读写方式打开文件,该文件必须存在。
读写打开一个二进制文件,允许读数据。
读写打开一个文本文件,允许读和写。
打开只写文件,若文件存在则文件长度清为0,即该文件内容会消失。若文件不存在则建立该文件。
打开可读写文件,若文件存在则文件长度清为零,即该文件内容会消失。若文件不存在则建立该文件。
以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。(EOF符保留)
以附加方式打开可读写的文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾后,即文件原先的内容会被保留。 (原来的EOF符不保留)
只写打开或新建一个二进制文件;只允许写数据。
读写打开或建立一个二进制文件,允许读和写。
读写打开或着建立一个文本文件;允许读写。
读写打开一个文本文件,允许读或在文本末追加数据。
读写打开一个二进制文件,允许读或在文件末追加数据。
现在对上面的文件打开方式做个总结:
文件使用方式由r,w,a,t,b,+六个字符拼成,各字符的含义是:
&&& r(read): 读
&&& w(write): 写
&&& a(append): 追加
&&& t(text): 文本文件,可省略不写
&&& b(banary): 二进制文件
&&& +: 读和写
返回值
&&&&如果文件顺利打开,返回指向该流的文件指针。如果文件打开失败则返回NULL,并把错误代码存在errno中。
&&&&一般而言,打开文件后会作一些文件读取或写入的动作,若打开文件失败,接下来的读写动作也无法顺利进行,所以一般在fopen()后作错误判断及处理。
(2)fread()函数和fwrite()函数:(可以用来实现对数据块的操作)
1.一般调用形式
& fread(buffer,size,count,fp);
& fwrite(buffer,size,count,fp);
& (1)buffer:是一个指针,对fread来说,它是读入数据的存放地址。对fwrite来说,是要输出数据的地址。
& (2)size:要读写的字节数;
& (3)count:要进行读写多少个size字节的数据项;
& (4)fp:文件型指针。
C语言还提供了用于整块数据的读写函数。 可用来读写一组数据,如一个数组元素,一个结构变量的值等。读数据块函数调用的一般形式为: fread(buffer,size,count,fp); 写数据块函数调用的一般形式为: fwrite(buffer,size,count,fp); 其中buffer是一个指针,在fread函数中,它表示存放输入数据的首地址。在fwrite函数中,它表示存放输出数据的首地址。
size 表示数据块的字节数。count 表示要读写的数据块块数。fp 表示文件指针。
例如:fread(fa,4,5,fp); 其意义是从fp所指的文件中,每次读4个字节(一个实数)送入实数组fa中,连续读5次,即读5个实数到fa中。
(3)fgetc()和fputc():字符读写函数
fgetc函数(getc函数)
&(1)一般调用形式
& & & & ch=fgetc(fp);
& & & & 从指定的文件读入一个字符,即从fp所指向的文件中读入一个字符赋给ch。
(3)返回值
& & & & 成功:返回值所得到的字符;
& & & & 失败:返回EOF(-1)。
fputc函数():
(1)一般调用形式
&fputc(ch,fp);
把一个字符写到磁盘文件上去,即将字符ch输出到fp所指向的文件中去。
(3)返回值
成功:返回值就是输出的字符;
失败:返回EOF(-1)。
说明:函数putchar()是在stdio.h中用预处理命令定义的宏,即:
#define putchar(c) & & fputc(c,stdout)
4、fgets()和fputs()函数:读写字符串函数
(1)fgets():char *fgets(char
*str, int num, FILE *fp)&
参数说明:str: 保存从文件读取出来的字符串&&&&&&&
& & & & &fp: 待读文件的文件指针
& & & & &num: 表示从文件中读出的字符串不超过 n-1个字符。在读入的最后一个字符后加上串结束标志'\0'
(2)fputs(char * s,FILE * stream);
5、fscanf()和fprintf()函数:格式化读写函数
(1)fprintf()函数:输出格式化字符串到流或者是将格式化后的字符串写到输出流(文件)
原型:int fprintf( FILE
*stream, const char *format [, argument ]…);&
例子:fprintf(fp, &%s %s %d %f&, str1,str2, a, b) ;
(2)fscanf()函数:输出文件中的内容到某个变量中。
int fscanf(FILE *stream, char *format,[argument...]);
  int fscanf(文件指针,格式字符串,输入列表);
  for example:
  FILE *
  char a[];
  fscanf(fp,&%s%d%lf&,a,&b,&c)
  返回值:整型,数值等于[argument...]的个数
6、ftell()函数:得到流式文件的当前读写位置,其返回值是当前读写位置偏离文件头部的字节数。
原型:long ftell(FILE *fp)
7、&fseek()函数:把fp的文件读写位置指针移到指定的位置。
int fseek(FILE *fp,long offset,int origin);
origin指的是“起始点”,它有三个常量的值,如下:
起始点对应的数字&& 代表的文件位置
SEEK_SET&0&& 文件开头
SEEK_CUR&1&& 文件当前位置
SEEK_END&2&& 文件末尾
8、&rewind()函数:将文件指针重新指向一个流的开头
原型:int rewind(FILE *stream);&
例子:一般我们会通过下面的方法来获取文件中字符的个数:
&&& FILE *fs=fopen(&C:\1.txt&,&r&);//创建文件流
&&& long length=0;//声明文件长度
&&& fseek(fs,0,SEEK_END);//将文件内部指针放到文件最后面
&&& length=ftell(fs);//读取文件指针的位置,得到文件字符的个数
&&& rewind(fs);//将文件指针重置到文件最前面
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:349143次
积分:2869
积分:2869
排名:第8575名
原创:43篇
转载:15篇
评论:24条
(1)(2)(2)(1)(1)(11)(4)(3)(25)(8)有谁能告诉我,这什么情况..._c语言吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:455,356贴子:
有谁能告诉我,这什么情况...收藏
/* * stdio.h * This file has no copyright assigned and is placed in the Public Domain. * This file is a part of the mingw-runtime package. * N refer to the file DISCLAIMER within the package. * * Definitions of types and prototypes of functions for standard input and * output. * * NOTE: The file manipulation functions provided by Microsoft seem to * work with either slash (/) or backslash (\) as the directory separator. * */#ifndef _STDIO_H_#define_STDIO_H_/* All the headers include this file. */#include &_mingw.h&#ifndef RC_INVOKED#define __need_size_t#define __need_NULL#define __need_wchar_t#define__need_wint_t#include &stddef.h&#define __need___va_list#include &stdarg.h&#endif/* Not RC_INVOKED *//* Flags for the iobuf structure
*/#define_IOREAD1 /* currently reading */#define_IOWRT2 /* currently writing */#define_IORW0x0080 /* opened as &r+w& *//* * The three standard file pointers provided by the run time library. * NOTE: These will go to the bit-bucket silently in GUI applications! */#defineSTDIN_FILENO0#defineSTDOUT_FILENO1#defineSTDERR_FILENO2/* Returned by various functions on end of file condition or error. */#defineEOF(-1)/* * The maximum length of a file name. You should use GetVolumeInformation * instead of this constant. But hey, this works. * Also defined in io.h. */#ifndef FILENAME_MAX#defineFILENAME_MAX(260)#endif/* * The maximum number of files that may be open at once. I have set this to * a conservative number. The actual value may be higher. */#define FOPEN_MAX(20)/* After creating this many names, tmpnam and tmpfile return NULL */#define TMP_MAX32767/* * Tmpnam, tmpfile and, sometimes, _tempnam try to create * temp files in the root directory of the current drive * (not in pwd, as suggested by some older MS doc's). * Redefining these macros does not effect the CRT functions. */#define _P_tmpdir
&\\&#ifndef __STRICT_ANSI__#define P_tmpdir _P_tmpdir#endif#define _wP_tmpdir
L&\\&/* * The maximum size of name (including NUL) that will be put in the user * supplied buffer caName for tmpnam. * Inferred from the size of the static buffer returned by tmpnam * when passed a NULL argument. May actually be smaller. */#define L_tmpnam (16)#define _IOFBF
/* full buffered */#define _IOLBF
/* line buffered */#define _IONBF
/* not buffered */#define _IOMYBUF
/* stdio malloc()'d buffer */#define _IOEOF
/* EOF reached on read */#define _IOERR
/* I/O error from system */#define _IOSTRG
/* Strange or no file descriptor */#ifdef _POSIX_SOURCE# define _IOAPPEND 0x0200#endif/* * The buffer size as used by setbuf such that it is equivalent to * (void) setvbuf(fileSetBuffer, caBuffer, _IOFBF, BUFSIZ). */#defineBUFSIZ512/* Constants for nOrigin indicating the position relative to which fseek * sets the file position.
Defined unconditionally since ISO and POSIX * say they are defined here.
*/#define SEEK_SET 0#define SEEK_CUR 1#define SEEK_END 2#ifndefRC_INVOKED#ifndef __VALIST#ifdef __GNUC__#define __VALIST __gnuc_va_list#else#define __VALIST char*#endif#endif /* defined __VALIST
*//* * The structure underlying the FILE type. * * Some believe that nobody in their right mind should make use of the * internals of this structure. Provided by Pedro A. Aranda Gutiirrez * &paag@tid.es&. */#ifndef _FILE_DEFINED#define_FILE_DEFINEDtypedef struct _iobuf{char*_int_char*_int_int_int_int_char*_} FILE;#endif/* Not _FILE_DEFINED *//* * The standard file handles */#ifndef __DECLSPEC_SUPPORTEDextern FILE (*_imp___iob)[];/* A pointer to an array of FILE */#define _iob(*_imp___iob)/* An array of FILE */#else /* __DECLSPEC_SUPPORTED */__MINGW_IMPORT FILE _iob[];/* An array of FILE imported from DLL. */#endif /* __DECLSPEC_SUPPORTED */#define stdin(&_iob[STDIN_FILENO])#define stdout(&_iob[STDOUT_FILENO])#define stderr(&_iob[STDERR_FILENO])#ifdef __cplusplusextern &C& {#endif/* * File Operations */_CRTIMP FILE* __cdecl __MINGW_NOTHROW fopen (const char*, const char*);_CRTIMP FILE* __cdecl __MINGW_NOTHROWfreopen (const char*, const char*, FILE*);_CRTIMP int __cdecl __MINGW_NOTHROWfflush (FILE*);_CRTIMP int __cdecl __MINGW_NOTHROWfclose (FILE*);/* MS puts remove & rename (but not wide versions) in io.h
also */_CRTIMP int __cdecl __MINGW_NOTHROWremove (const char*);_CRTIMP int __cdecl __MINGW_NOTHROWrename (const char*, const char*);_CRTIMP FILE* __cdecl __MINGW_NOTHROWtmpfile (void);_CRTIMP char* __cdecl __MINGW_NOTHROWtmpnam (char*);#ifndef __STRICT_ANSI___CRTIMP char* __cdecl __MINGW_NOTHROW_tempnam (const char*, const char*);_CRTIMP int __cdecl __MINGW_NOTHROW_rmtmp(void);_CRTIMP int __cdecl __MINGW_NOTHROW_unlink (const char*);#ifndefNO_OLDNAMES_CRTIMP char* __cdecl __MINGW_NOTHROWtempnam (const char*, const char*);_CRTIMP int __cdecl __MINGW_NOTHROWrmtmp(void);_CRTIMP int __cdecl __MINGW_NOTHROWunlink (const char*);#endif#endif /* __STRICT_ANSI__ */_CRTIMP int __cdecl __MINGW_NOTHROWsetvbuf (FILE*, char*, int, size_t);_CRTIMP void __cdecl __MINGW_NOTHROWsetbuf (FILE*, char*);/* * Formatted Output */_CRTIMP int __cdecl __MINGW_NOTHROWfprintf (FILE*, const char*, ...);_CRTIMP int __cdecl __MINGW_NOTHROWprintf (const char*, ...);_CRTIMP int __cdecl __MINGW_NOTHROWsprintf (char*, const char*, ...);_CRTIMP int __cdecl __MINGW_NOTHROW_snprintf (char*, size_t, const char*, ...);_CRTIMP int __cdecl __MINGW_NOTHROWvfprintf (FILE*, const char*, __VALIST);_CRTIMP int __cdecl __MINGW_NOTHROWvprintf (const char*, __VALIST);_CRTIMP int __cdecl __MINGW_NOTHROWvsprintf (char*, const char*, __VALIST);_CRTIMP int __cdecl __MINGW_NOTHROW_vsnprintf (char*, size_t, const char*, __VALIST);#ifndef __NO_ISOCEXT
/* externs in libmingwex.a *//* * Microsoft does not provide implementations for the following, * which are required by C99.
Note in particular that the corresponding * Microsoft implementations of _snprintf() and _vsnprintf() are *not* * compatible with C99, b if you want the MSVCRT * behaviour, you *must* use the Microsoft uglified names. */int __cdecl __MINGW_NOTHROW snprintf(char *, size_t, const char *, ...);int __cdecl __MINGW_NOTHROW vsnprintf (char *, size_t, const char *, __VALIST);int __cdecl __MINGW_NOTHROW vscanf (const char * __restrict__, __VALIST);int __cdecl __MINGW_NOTHROW vfscanf (FILE * __restrict__, const char * __restrict__,
__VALIST);int __cdecl __MINGW_NOTHROW vsscanf (const char * __restrict__,
const char * __restrict__, __VALIST);#endif
/* !__NO_ISOCEXT *//* * Formatted Input */_CRTIMP int __cdecl __MINGW_NOTHROWfscanf (FILE*, const char*, ...);_CRTIMP int __cdecl __MINGW_NOTHROWscanf (const char*, ...);_CRTIMP int __cdecl __MINGW_NOTHROWsscanf (const char*, const char*, ...);/* * Character Input and Output Functions */_CRTIMP int __cdecl __MINGW_NOTHROWfgetc (FILE*);_CRTIMP char* __cdecl __MINGW_NOTHROWfgets (char*, int, FILE*);_CRTIMP int __cdecl __MINGW_NOTHROWfputc (int, FILE*);_CRTIMP int __cdecl __MINGW_NOTHROWfputs (const char*, FILE*);_CRTIMP char* __cdecl __MINGW_NOTHROWgets (char*);_CRTIMP int __cdecl __MINGW_NOTHROWputs (const char*);_CRTIMP int __cdecl __MINGW_NOTHROWungetc (int, FILE*);/* Traditionally, getc and putc are defined as macros. but the
standard doesn't say that they must be macros.
We use inline functions here to allow the fast versions
to be used in C++ with namespace qualification, eg., ::getc.
_filbuf and _flsbuf
are not thread-safe. */_CRTIMP int __cdecl __MINGW_NOTHROW_filbuf (FILE*);_CRTIMP int __cdecl __MINGW_NOTHROW_flsbuf (int, FILE*);#if !defined _MT__CRT_INLINE int __cdecl __MINGW_NOTHROW getc (FILE* __F){
return (--__F-&_cnt &= 0)
(int) (unsigned char) *__F-&_ptr++
: _filbuf (__F);}__CRT_INLINE int __cdecl __MINGW_NOTHROW putc (int __c, FILE* __F){
return (--__F-&_cnt &= 0)
(int) (unsigned char) (*__F-&_ptr++ = (char)__c)
_flsbuf (__c, __F);}__CRT_INLINE int __cdecl __MINGW_NOTHROW getchar (void){
return (--stdin-&_cnt &= 0)
(int) (unsigned char) *stdin-&_ptr++
: _filbuf (stdin);}__CRT_INLINE int __cdecl __MINGW_NOTHROW putchar(int __c){
return (--stdout-&_cnt &= 0)
(int) (unsigned char) (*stdout-&_ptr++ = (char)__c)
_flsbuf (__c, stdout);}#else
/* Use library functions.
*/_CRTIMP int __cdecl __MINGW_NOTHROWgetc (FILE*);_CRTIMP int __cdecl __MINGW_NOTHROWputc (int, FILE*);_CRTIMP int __cdecl __MINGW_NOTHROWgetchar (void);_CRTIMP int __cdecl __MINGW_NOTHROWputchar (int);#endif/* * Direct Input and Output Functions */_CRTIMP size_t __cdecl __MINGW_NOTHROWfread (void*, size_t, size_t, FILE*);_CRTIMP size_t __cdecl __MINGW_NOTHROWfwrite (const void*, size_t, size_t, FILE*);/* * File Positioning Functions */_CRTIMP int __cdecl __MINGW_NOTHROWfseek (FILE*, long, int);_CRTIMP long __cdecl __MINGW_NOTHROWftell (FILE*);_CRTIMP void __cdecl __MINGW_NOTHROWrewind (FILE*);#if __MSVCRT_VERSION__ &= 0x800_CRTIMP int __cdecl __MINGW_NOTHROW_fseek_nolock (FILE*, long, int);_CRTIMP long __cdecl __MINGW_NOTHROW_ftell_nolock (FILE*);_CRTIMP int __cdecl __MINGW_NOTHROW_fseeki64 (FILE*, __int64, int);_CRTIMP __int64 __cdecl __MINGW_NOTHROW_ftelli64 (FILE*);_CRTIMP int __cdecl __MINGW_NOTHROW_fseeki64_nolock (FILE*, __int64, int);_CRTIMP __int64 __cdecl __MINGW_NOTHROW_ftelli64_nolock (FILE*);#endif#ifdef __USE_MINGW_FSEEK
/* These are in libmingwex.a *//* * Workaround for limitations on win9x where a file contents are * not zero'd out if you seek past the end and then write. */int __cdecl __MINGW_NOTHROW __mingw_fseek (FILE *, long, int);size_t __cdecl __MINGW_NOTHROW __mingw_fwrite (const void*, size_t, size_t, FILE*);#define fseek(fp, offset, whence)
__mingw_fseek(fp, offset, whence)#define fwrite(buffer, size, count, fp)
__mingw_fwrite(buffer, size, count, fp)#endif /* __USE_MINGW_FSEEK *//* * An opaque data type used for storing file positions... The contents of * this type are unknown, but we (the compiler) need to know the size * because the programmer using fgetpos and fsetpos will be setting aside * storage for fpos_t structres. Actually I tested using a byte array and * it is fairly evident that the fpos_t type is a long (in CRTDLL.DLL). * Perhaps an unsigned long? TODO? It's definitely a 64-bit number in * MSVCRT however, and for now `long long' will do. */#ifdef __MSVCRT__typedef long long fpos_t;#elsetypedef longfpos_t;#endif_CRTIMP int __cdecl __MINGW_NOTHROWfgetpos(FILE*, fpos_t*);_CRTIMP int __cdecl __MINGW_NOTHROWfsetpos (FILE*, const fpos_t*);/* * Error Functions */_CRTIMP int __cdecl __MINGW_NOTHROWfeof (FILE*);_CRTIMP int __cdecl __MINGW_NOTHROWferror (FILE*);#ifdef __cplusplusinline int __cdecl __MINGW_NOTHROW feof (FILE* __F)
{ return __F-&_flag & _IOEOF; }inline int __cdecl __MINGW_NOTHROW ferror (FILE* __F)
{ return __F-&_flag & _IOERR; }#else#define feof(__F)
((__F)-&_flag & _IOEOF)#define ferror(__F)
((__F)-&_flag & _IOERR)#endif_CRTIMP void __cdecl __MINGW_NOTHROWclearerr (FILE*);_CRTIMP void __cdecl __MINGW_NOTHROWperror (const char*);#ifndef __STRICT_ANSI__/* * Pipes */_CRTIMP FILE* __cdecl __MINGW_NOTHROW_popen (const char*, const char*);_CRTIMP int __cdecl __MINGW_NOTHROW_pclose (FILE*);#ifndef NO_OLDNAMES_CRTIMP FILE* __cdecl __MINGW_NOTHROWpopen (const char*, const char*);_CRTIMP int __cdecl __MINGW_NOTHROWpclose (FILE*);#endif/* * Other Non ANSI functions */_CRTIMP int __cdecl __MINGW_NOTHROW_flushall (void);_CRTIMP int __cdecl __MINGW_NOTHROW_fgetchar (void);_CRTIMP int __cdecl __MINGW_NOTHROW_fputchar (int);_CRTIMP FILE* __cdecl __MINGW_NOTHROW_fdopen (int, const char*);_CRTIMP int __cdecl __MINGW_NOTHROW_fileno (FILE*);_CRTIMP int __cdecl __MINGW_NOTHROW_fcloseall(void);_CRTIMP FILE* __cdecl __MINGW_NOTHROW_fsopen(const char*, const char*, int);#ifdef __MSVCRT___CRTIMP int __cdecl __MINGW_NOTHROW_getmaxstdio(void);_CRTIMP int __cdecl __MINGW_NOTHROW_setmaxstdio(int);#endif#if __MSVCRT_VERSION__ &= 0x800_CRTIMP int __cdecl __MINGW_NOTHROW _set_printf_count_output(int);_CRTIMP int __cdecl __MINGW_NOTHROW _get_printf_count_output(void);#endif#ifndef _NO_OLDNAMES_CRTIMP int __cdecl __MINGW_NOTHROWfgetchar (void);_CRTIMP int __cdecl __MINGW_NOTHROWfputchar (int);_CRTIMP FILE* __cdecl __MINGW_NOTHROWfdopen (int, const char*);_CRTIMP int __cdecl __MINGW_NOTHROWfileno (FILE*);#endif/* Not _NO_OLDNAMES */#define _fileno(__F) ((__F)-&_file)#ifndef _NO_OLDNAMES#define fileno(__F) ((__F)-&_file)#endif#if defined (__MSVCRT__) && !defined (__NO_MINGW_LFS)#include &sys/types.h&__CRT_INLINE FILE* __cdecl __MINGW_NOTHROW fopen64 (const char* filename, const char* mode){
return fopen (filename, mode); }int __cdecl __MINGW_NOTHROW fseeko64 (FILE*, off64_t, int);#ifdef __USE_MINGW_FSEEKint __cdecl __MINGW_NOTHROW __mingw_fseeko64 (FILE *, off64_t, int);#define fseeko64(fp, offset, whence)
__mingw_fseeko64(fp, offset, whence)#endif__CRT_INLINE off64_t __cdecl __MINGW_NOTHROW ftello64 (FILE * stream){
if (fgetpos(stream, &pos))
return ((off64_t) pos);}#endif /* __NO_MINGW_LFS */#endif/* Not __STRICT_ANSI__ *//* Wide
versions */#ifndef _WSTDIO_DEFINED/*
also in wchar.h - keep in sync */_CRTIMP int __cdecl __MINGW_NOTHROWfwprintf (FILE*, const wchar_t*, ...);_CRTIMP int __cdecl __MINGW_NOTHROWwprintf (const wchar_t*, ...);_CRTIMP int __cdecl __MINGW_NOTHROWswprintf (wchar_t*, const wchar_t*, ...);_CRTIMP int __cdecl __MINGW_NOTHROW_snwprintf (wchar_t*, size_t, const wchar_t*, ...);_CRTIMP int __cdecl __MINGW_NOTHROWvfwprintf (FILE*, const wchar_t*, __VALIST);_CRTIMP int __cdecl __MINGW_NOTHROWvwprintf (const wchar_t*, __VALIST);_CRTIMP int __cdecl __MINGW_NOTHROWvswprintf (wchar_t*, const wchar_t*, __VALIST);_CRTIMP int __cdecl __MINGW_NOTHROW_vsnwprintf (wchar_t*, size_t, const wchar_t*, __VALIST);_CRTIMP int __cdecl __MINGW_NOTHROWfwscanf (FILE*, const wchar_t*, ...);_CRTIMP int __cdecl __MINGW_NOTHROWwscanf (const wchar_t*, ...);_CRTIMP int __cdecl __MINGW_NOTHROWswscanf (const wchar_t*, const wchar_t*, ...);_CRTIMP wint_t __cdecl __MINGW_NOTHROWfgetwc (FILE*);_CRTIMP wint_t __cdecl __MINGW_NOTHROWfputwc (wchar_t, FILE*);_CRTIMP wint_t __cdecl __MINGW_NOTHROWungetwc (wchar_t, FILE*);#ifdef __MSVCRT__ _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW fgetws (wchar_t*, int, FILE*);_CRTIMP int __cdecl __MINGW_NOTHROWfputws (const wchar_t*, FILE*);_CRTIMP wint_t __cdecl __MINGW_NOTHROWgetwc (FILE*);_CRTIMP wint_t __cdecl __MINGW_NOTHROWgetwchar (void);_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _getws (wchar_t*);_CRTIMP wint_t __cdecl __MINGW_NOTHROWputwc (wint_t, FILE*);_CRTIMP int __cdecl __MINGW_NOTHROW_putws (const wchar_t*);_CRTIMP wint_t __cdecl __MINGW_NOTHROWputwchar (wint_t);_CRTIMP FILE* __cdecl __MINGW_NOTHROW_wfdopen(int, wchar_t *);_CRTIMP FILE* __cdecl __MINGW_NOTHROW_wfopen (const wchar_t*, const wchar_t*);_CRTIMP FILE* __cdecl __MINGW_NOTHROW_wfreopen (const wchar_t*, const wchar_t*, FILE*);_CRTIMP FILE* __cdecl __MINGW_NOTHROW_wfsopen (const wchar_t*, const wchar_t*, int);_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _wtmpnam (wchar_t*);_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _wtempnam (const wchar_t*, const wchar_t*);_CRTIMP int __cdecl __MINGW_NOTHROW_wrename (const wchar_t*, const wchar_t*);_CRTIMP int __cdecl __MINGW_NOTHROW_wremove (const wchar_t*);_CRTIMP void __cdecl __MINGW_NOTHROW_wperror (const wchar_t*);_CRTIMP FILE* __cdecl __MINGW_NOTHROW_wpopen (const wchar_t*, const wchar_t*);#endif/* __MSVCRT__ */#ifndef __NO_ISOCEXT
/* externs in libmingwex.a */int __cdecl __MINGW_NOTHROW snwprintf (wchar_t* s, size_t n, const wchar_t*
format, ...);__CRT_INLINE int __cdecl __MINGW_NOTHROWvsnwprintf (wchar_t* s, size_t n, const wchar_t* format, __VALIST arg)
{ return _vsnwprintf ( s, n, format, arg);}int __cdecl __MINGW_NOTHROW vwscanf (const wchar_t * __restrict__, __VALIST);int __cdecl __MINGW_NOTHROW vfwscanf (FILE * __restrict__,
const wchar_t * __restrict__, __VALIST);int __cdecl __MINGW_NOTHROW vswscanf (const wchar_t * __restrict__,
const wchar_t * __restrict__, __VALIST);#endif#define _WSTDIO_DEFINED#endif /* _WSTDIO_DEFINED */#ifndef __STRICT_ANSI__#ifdef __MSVCRT__#ifndef NO_OLDNAMES_CRTIMP FILE* __cdecl __MINGW_NOTHROWwpopen (const wchar_t*, const wchar_t*);#endif /* not NO_OLDNAMES */#endif /* MSVCRT runtime *//* * Other Non ANSI wide functions */_CRTIMP wint_t __cdecl __MINGW_NOTHROW_fgetwchar (void);_CRTIMP wint_t __cdecl __MINGW_NOTHROW_fputwchar (wint_t);_CRTIMP int __cdecl __MINGW_NOTHROW_getw (FILE*);_CRTIMP int __cdecl __MINGW_NOTHROW_putw (int, FILE*);#ifndef _NO_OLDNAMES_CRTIMP wint_t __cdecl __MINGW_NOTHROWfgetwchar (void);_CRTIMP wint_t __cdecl __MINGW_NOTHROWfputwchar (wint_t);_CRTIMP int __cdecl __MINGW_NOTHROWgetw (FILE*);_CRTIMP int __cdecl __MINGW_NOTHROWputw (int, FILE*);#endif/* Not _NO_OLDNAMES */#endif /* __STRICT_ANSI */#ifdef __cplusplus}#endif#endif/* Not RC_INVOKED */#endif /* _STDIO_H_ */
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或}

我要回帖

更多关于 fputc fgetc 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信