stdio.h c头文件

2024-06-21 04:38
文章标签 头文件 stdio

本文主要是介绍stdio.h c头文件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

       一般会把用来#include的文件的扩展名叫 .h,称其为头文件。 #include文件的目的就是把多个编译单元(也就是c或者cpp文件)公用的内容,单独放在一个文件里减少整体代码尺寸;或者提供跨工程公共代码。


stdio 就是指 “standard input & output"(标准输入输出)所以,源代码中如用到标准输入输出函数时,就要包含这个头文件


标准函数:

int getchar() //从标准输入设备读入一个字符
int putchar() //向标准输出设备写出一个字符
int scanf(char *format[,argument…]) //从标准输入设备读入格式化后的数据
int printf(char *format[,argument…]) //向标准输出设备输出格式化字符串
char *gets(char *string) //从标准输入设备读入一个字符串
int puts(char *string) //向标准输出设备输出一个字符串
int sprintf(char*string,char*format[,…]) //把格式化的数据写入某个字符串缓冲区

文件说明:

/*
* 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.
* No warranty is given; 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 _IOREAD 1 /* currently reading */
#define _IOWRT 2 /* currently writing */
#define _IORW 0x0080 /* 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!
*/
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
/* Returned by various functions on end of file condition or error. */
#define EOF (-1)
/*
* The maximum length of a file name. You should useGetVolumeInformation
* instead of this constant. But hey, this works.
* Also defined in io.h.
*/
#ifndef FILENAME_MAX
#define FILENAME_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,tmpnamand tmpfile return NULL */
#defineTMP_MAX 32767
/*
* Tmpnam, tmpfile and, sometimes, _tempnamtry 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 fortmpnam.
* 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 0x0000 /* full buffered */
#define _IOLBF 0x0040 /* line buffered */
#define _IONBF 0x0004 /* not buffered */
#define _IOMYBUF 0x0008 /* stdio malloc()'d buffer */
#define _IOEOF 0x0010 /* EOF reached on read */
#define_IOERR 0x0020 /* I/O error from system */
#define_IOSTRG 0x0040 /* Strange or no file descriptor */
#ifdef _POSIX_SOURCE
# define _IOAPPEND 0x0200
#endif
/*
* The buffer size as used bysetbufsuch that it is equivalent to
* (void) setvbuf(fileSetBuffer, caBuffer, _IOFBF, BUFSIZ).
*/
#define BUFSIZ 512
/* Constants for nOrigin indicating the position relative to which fseek
* sets the file position. Enclosed in ifdefs because io.h could also
* define them. (Though not anymore since io.h includes this file now.) */
#ifndef SEEK_SET
#define SEEK_SET (0)
#endif
#ifndef SEEK_CUR
#define SEEK_CUR (1)
#endif
#ifndef SEEK_END
#define SEEK_END (2)
#endif
#ifndef RC_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
*/
#ifndef _FILE_DEFINED
#define _FILE_DEFINED

结构体定义:

typedef struct _iobuf
{
char* _ptr;
int _cnt;
char* _base;
int _flag;
int _file;
int _charbuf;
int _bufsiz;
char* _tmpfname;
} FILE;
#endif /* Not _FILE_DEFINED */
/*
* The standard file handles
*/
#ifndef __DECLSPEC_SUPPORTED
extern 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 __cplusplus
extern "C" {
#endif
/*
* File Operations
*/
_CRTIMP FILE* __cdecl fopen (const char*, const char*);
_CRTIMP FILE* __cdecl freopen (const char*, const char*, FILE*);
_CRTIMP int __cdecl fflush (FILE*);
_CRTIMP int __cdecl fclose (FILE*);
/* MS puts remove & rename (but not wide versions) in io.h also */
_CRTIMP int __cdecl remove (const char*);
_CRTIMP int __cdecl rename (const char*, const char*);
_CRTIMP FILE* __cdecl tmpfile (void);
_CRTIMP char* __cdecltmpnam(char*);
#ifndef __STRICT_ANSI__
_CRTIMP char* __cdecl _tempnam(const char*, const char*);
_CRTIMP int __cdecl _rmtmp(void);
#ifndef NO_OLDNAMES
_CRTIMP char* __cdecltempnam(const char*, const char*);
_CRTIMP int __cdecl rmtmp(void);
#endif
#endif /* __STRICT_ANSI__ */
_CRTIMP int __cdecl setvbuf (FILE*, char*, int,size_t);
_CRTIMP void __cdeclsetbuf(FILE*, char*);
/*
* Formatted Output
*/
_CRTIMP int __cdecl fprintf (FILE*, const char*, ...);
_CRTIMP int __cdecl printf (const char*, ...);
_CRTIMP int __cdecl sprintf (char*, const char*, ...);
_CRTIMP int __cdecl _snprintf (char*,size_t, const char*, ...);
_CRTIMP int __cdecl vfprintf (FILE*, const char*, __VALIST);
_CRTIMP int __cdecl vprintf (const char*, __VALIST);
_CRTIMP int __cdecl vsprintf (char*, const char*, __VALIST);
_CRTIMP int __cdecl _vsnprintf (char*,size_t, const char*, __VALIST);
#ifndef __NO_ISOCEXT /* externs in libmingwex.a */
int __cdecl snprintf(char* s,size_tn, const char* format, ...);
__CRT_INLINE int __cdecl
vsnprintf (char* s,size_tn, const char* format, __VALIST arg)
{ return _vsnprintf ( s, n, format, arg); }
int __cdeclvscanf(const char * __restrict__, __VALIST);
int __cdeclvfscanf(FILE * __restrict__, const char * __restrict__,
__VALIST);
int __cdeclvsscanf(const char * __restrict__,
const char * __restrict__, __VALIST);
#endif
/*
* Formatted Input
*/
_CRTIMP int __cdecl fscanf (FILE*, const char*, ...);
_CRTIMP int __cdecl scanf (const char*, ...);
_CRTIMP int __cdecl sscanf (const char*, const char*, ...);
/*
* Character Input and Output Functions
*/
_CRTIMP int __cdecl fgetc (FILE*);
_CRTIMP char* __cdecl fgets (char*, int, FILE*);
_CRTIMP int __cdecl fputc (int, FILE*);
_CRTIMP int __cdecl fputs (const char*, FILE*);
_CRTIMP char* __cdecl gets (char*);
_CRTIMP int __cdecl puts (const char*);
_CRTIMP int __cdeclungetc(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 _filbuf (FILE*);
_CRTIMP int __cdecl _flsbuf (int, FILE*);
#if !defined _MT
__CRT_INLINE int __cdecl getc (FILE* __F)
{
return (--__F->_cnt >= 0)
? (int) (unsigned char) *__F->_ptr++
: _filbuf (__F);
}
__CRT_INLINE int __cdecl putc (int __c, FILE* __F)
{
return (--__F->_cnt >= 0)
? (int) (unsigned char) (*__F->_ptr++ = (char)__c)
: _flsbuf (__c, __F);
}
__CRT_INLINE int __cdecl getchar (void)
{
return (--stdin->_cnt >= 0)
? (int) (unsigned char) *stdin->_ptr++
: _filbuf (stdin);
}
__CRT_INLINE int __cdecl putchar(int __c)
{
return (--stdout->_cnt >= 0)
? (int) (unsigned char) (*stdout->_ptr++ = (char)__c)
: _flsbuf (__c, stdout);}
#else /* Use library functions. */
_CRTIMP int __cdecl getc (FILE*);
_CRTIMP int __cdecl putc (int, FILE*);
_CRTIMP int __cdecl getchar (void);
_CRTIMP int __cdecl putchar (int);
#endif
/*
* Direct Input and Output Functions
*/
_CRTIMPsize_t__cdecl fread (void*,size_t,size_t, FILE*);
_CRTIMPsize_t__cdecl fwrite (const void*,size_t, size_t, FILE*);
/*
* File Positioning Functions
*/
_CRTIMP int __cdecl fseek (FILE*, long, int);
_CRTIMP long __cdecl ftell (FILE*);
_CRTIMP void __cdecl rewind (FILE*);
#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_fseek (FILE *, long, int);
int __cdecl __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 usingfgetposandfsetposwill 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;
#else
typedef long fpos_t;
#endif
_CRTIMP int __cdeclfgetpos(FILE*, fpos_t*);
_CRTIMP int __cdeclfsetpos(FILE*, const fpos_t*);
/*
* Error Functions
*/
_CRTIMP int __cdecl feof (FILE*);
_CRTIMP int __cdecl ferror (FILE*);
#ifdef __cplusplus
inline int __cdecl feof (FILE* __F)
{ return __F->_flag & _IOEOF; }
inline int __cdecl ferror (FILE* __F)
{ return __F->_flag & _IOERR; }
#else
#define feof(__F) ((__F)->_flag & _IOEOF)
#define ferror(__F) ((__F)->_flag & _IOERR)
#endif
_CRTIMP void __cdeclclearerr(FILE*);
_CRTIMP void __cdecl perror (const char*);
#ifndef __STRICT_ANSI__
/*
* Pipes
*/
_CRTIMP FILE* __cdecl _popen (const char*, const char*);
_CRTIMP int __cdecl _pclose (FILE*);
#ifndef NO_OLDNAMES
_CRTIMP FILE* __cdecl popen (const char*, const char*);
_CRTIMP int __cdecl pclose (FILE*);
#endif
/*
* Other Non ANSI functions
*/
_CRTIMP int __cdecl _flushall (void);
_CRTIMP int __cdecl _fgetchar(void);
_CRTIMP int __cdecl _fputchar(int);
_CRTIMP FILE* __cdecl _fdopen(int, const char*);
_CRTIMP int __cdecl _fileno (FILE*);
_CRTIMP int __cdecl _fcloseall(void);
_CRTIMP FILE* __cdecl _fsopen(const char*, const char*, int);
#ifdef __MSVCRT__
_CRTIMP int __cdecl _getmaxstdio(void);
_CRTIMP int __cdecl _setmaxstdio(int);
#endif
#ifndef _NO_OLDNAMES
_CRTIMP int __cdeclfgetchar(void);
_CRTIMP int __cdeclfputchar(int);
_CRTIMP FILE* __cdeclfdopen(int, const char*);
_CRTIMP int __cdecl fileno (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 fopen64 (const char* filename, const char* mode)
{
return fopen (filename, mode);
}
int __cdecl fseeko64 (FILE*, off64_t, int);
#ifdef __USE_MINGW_FSEEK
int __cdecl __mingw_fseeko64 (FILE *, off64_t, int);
#define fseeko64(fp, offset, whence) __mingw_fseeko64(fp, offset, whence)
#endif
__CRT_INLINE off64_t __cdecl ftello64 (FILE * stream)
{
fpos_t pos;
if (fgetpos(stream, &pos))
return -1LL;
else
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 fwprintf (FILE*, constwchar_t*, ...);
_CRTIMP int __cdecl wprintf (constwchar_t*, ...);
_CRTIMP int __cdeclswprintf(wchar_t*, constwchar_t*, ...);
_CRTIMP int __cdecl _snwprintf (wchar_t*,size_t, constwchar_t*, ...);
_CRTIMP int __cdecl vfwprintf (FILE*, constwchar_t*, __VALIST);
_CRTIMP int __cdecl vwprintf (constwchar_t*, __VALIST);
_CRTIMP int __cdecl vswprintf (wchar_t*, const wchar_t*, __VALIST);
_CRTIMP int __cdecl _vsnwprintf (wchar_t*,size_t, const wchar_t*, __VALIST);
_CRTIMP int __cdecl fwscanf (FILE*, constwchar_t*, ...);
_CRTIMP int __cdecl wscanf (const wchar_t*, ...);
_CRTIMP int __cdecl swscanf (constwchar_t*, const wchar_t*, ...);
_CRTIMP wint_t __cdecl fgetwc (FILE*);
_CRTIMP wint_t __cdecl fputwc (wchar_t, FILE*);
_CRTIMP wint_t __cdecl ungetwc (wchar_t, FILE*);
#ifdef __MSVCRT__
_CRTIMPwchar_t* __cdecl fgetws (wchar_t*, int, FILE*);
_CRTIMP int __cdecl fputws (constwchar_t*, FILE*);
_CRTIMP wint_t __cdecl getwc (FILE*);
_CRTIMP wint_t __cdecl getwchar (void);
_CRTIMPwchar_t* __cdecl _getws (wchar_t*);
_CRTIMP wint_t __cdecl putwc (wint_t, FILE*);
_CRTIMP int __cdecl _putws (constwchar_t*);
_CRTIMP wint_t __cdecl putwchar (wint_t);
_CRTIMP FILE* __cdecl _wfdopen(int,wchar_t*);
_CRTIMP FILE* __cdecl _wfopen (constwchar_t*, constwchar_t*);
_CRTIMP FILE* __cdecl _wfreopen (constwchar_t*, const wchar_t*, FILE*);
_CRTIMP FILE* __cdecl _wfsopen (constwchar_t*, const wchar_t*, int);
_CRTIMPwchar_t* __cdecl _wtmpnam (wchar_t*);
_CRTIMPwchar_t* __cdecl _wtempnam (constwchar_t*, constwchar_t*);
_CRTIMP int __cdecl _wrename (constwchar_t*, const wchar_t*);
_CRTIMP int __cdecl _wremove (const wchar_t*);
_CRTIMP void __cdecl _wperror (const wchar_t*);
_CRTIMP FILE* __cdecl _wpopen (constwchar_t*, const wchar_t*);
#endif /* __MSVCRT__ */
#ifndef __NO_ISOCEXT /* externs in libmingwex.a */
int __cdecl snwprintf (wchar_t* s, size_t n, const wchar_t* format, ...);
__CRT_INLINE int __cdecl
vsnwprintf (wchar_t* s, size_t n, const wchar_t* format, __VALIST arg)
{ return _vsnwprintf ( s, n, format, arg);}
int __cdecl vwscanf (constwchar_t* __restrict__, __VALIST);
int __cdecl vfwscanf (FILE * __restrict__,
constwchar_t* __restrict__, __VALIST);
int __cdecl vswscanf (constwchar_t* __restrict__,
constwchar_t* __restrict__, __VALIST);
#endif
#define _WSTDIO_DEFINED
#endif /* _WSTDIO_DEFINED */
#ifndef __STRICT_ANSI__
#ifdef __MSVCRT__
#ifndef NO_OLDNAMES
_CRTIMP FILE* __cdecl wpopen (const wchar_t*, const wchar_t*);
#endif /* not NO_OLDNAMES */
#endif /* MSVCRT runtime */
/*
* Other Non ANSI wide functions
*/
_CRTIMP wint_t __cdecl _fgetwchar (void);
_CRTIMP wint_t __cdecl _fputwchar (wint_t);
_CRTIMP int __cdecl _getw (FILE*);
_CRTIMP int __cdecl _putw(int, FILE*);
#ifndef _NO_OLDNAMES
_CRTIMP wint_t __cdecl fgetwchar (void);
_CRTIMP wint_t __cdecl fputwchar (wint_t);
_CRTIMP int __cdecl getw (FILE*);
_CRTIMP int __cdeclputw(int, FILE*);
#endif /* Not _NO_OLDNAMES */
#endif /* __STRICT_ANSI */
#ifdef __cplusplus
}
#endif
#endif /* Not RC_INVOKED */
#endif /* _STDIO_H_ */stdio.h所包含的函数:文件访问
fopen
freopen
fflush
fclose
二进制输入/输出
fread
fwrite
非格式化输入/输出
fgetc/getc
fputc/putc
ungetc
fgets
fputs
格式化输入/输出
scanf/fscanf/sscanf
printf/fprintf/sprintf
perror
文件定位
ftell
fseek
fgetpos
fsetpos
rewind
错误处理
feof
ferror
文件操作
remove
rename
tmpfile





这篇关于stdio.h c头文件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1080227

相关文章

ispunct函数讲解 <ctype.h>头文件函数

目录 1.头文件函数 2.ispunct函数使用  小心!VS2022不可直接接触,否则..!没有这个必要,方源一把抓住VS2022,顷刻 炼化! 1.头文件函数 以上函数都需要包括头文件<ctype.h> ,其中包括 ispunct 函数 #include<ctype.h> 2.ispunct函数使用 简述: ispunct函数一种判断字符是否为标点符号的函

解决C/C++ 头文件相互包含 问题的方法

所谓超前引用是指一个类型在定义之前就被用来定义变量和声明函数。 类A和类B需要彼此互相引用,这样必然有一个类会先被定义,而另外一个类后被定义,这样在 先被定义的类引用后被定义的类的时候,就导致了所谓的超前引用。 超前引用导致的错误有以下几种处理办法:   1) 使用类声明    在超前引用一个类之前,首先用一个特殊的语句说明该标识符是一个类名,即将被超前引用。其使用方法是

A-loam源码注释-头文件lidarFactor.hpp

本篇博客是A-loam学习的笔记,用于SLAM初学者一起学习。 lidarFactor.hpp #include <ceres/ceres.h> #include <ceres/rotation.h> #include <eigen3/Eigen/Dense> #include <pcl/point_cloud.h> #include <pcl/point_types.h> #include

解决Visual C++ 中相互包含头文件的问题

在编MFC应用程序时,经常会遇到头文件相互包含的问题,很是苦恼,于是便求助于强大的CSDN,得到如下答案:   方法一:利用友元类   我一共有两个类,由于要在两个类的头文件里互相应用对方,所以,在每一个类的头文件里面现包含另一个类的头文件,然后在该类的定义中声明另一个类为友元类。如下:    #include "B.h"      class CA: public CDialog

isxdigit函数讲解 <ctype.h>头文件函数

目录 1.头文件 2.isxdigit函数使用 方源一把抓住VS2022,顷刻  炼化!   1.头文件 以上函数都需要包括头文件<ctype.h> ,其中包括 isxdigit 函数 #include<ctype.h> 2.isxdigit函数使用 isxdigit 函数是判断字符是否为十六进制数字,这与isdigit很相似,isdigit用于判断字符是否为十进

在VMware虚拟机中编译文件的时候报错:找不到头文件ft2build.h

以下是报错内容,提示说找不到头文件ft2build.h freetype_show_font.c:12:10: fatal error: ft2build.h: No such file or directory  #include <ft2build.h>           ^~~~~~~~~~~~ compilation terminated.           在编译之前已

C语言通过MFC访问FTP,头文件个,宏和lib问题处理

1、预处理器定义 _LIB _CRT_SECURE_NO_WARNINGS _AFXDLL WIN32_LEAN_AND_MEAN

命令行gcc编译一个包含多个头文件的cpp项目并生成动态库.so

如题,现有项目路径状态大致如下: 1、项目中用到的第三方库(也就是头文件.h等内容),存放在./3rdparty路径下 。 2、源码路径(也就是主要的.cpp .h文件),存放在./src路径下。 在./src路径下执行命令: $ gcc -I 头文件路径1 -I 头文件路径2 -c xxx.cpp -fPIC -o xxx.o $ gcc -shared -o libxxx.so xxx

c语言头文件包含

所以关于头文件的写法个人 总结以下几点: (1) 对应的.c文件中写变量、函数的定义 (2) 对应的.h文件中写变量、函数的声明 (3) 如果有数据类型的定义 和 宏定义 ,请写的头文件(.h)中 (4) 头文件中一定加上#ifndef...#define....#endif之类的防止重包含的语句 (5) 模块的.c文件中别忘包含自己的.h文件************这句是重点 所以关于

iscntrl函数讲解 <ctype.h>头文件函数

目录 1.头文件 2.iscntrl函数 1.头文件 以上这些函数都属于头文件<ctype.h>中的函数,其中包括iscntrl函数 #include<ctype.h> 2.iscntrl函数 简述:iscntrl 函数用来判断字符是否为控制字符,控制字符为ASCII值在0x00到0x7f之间 控制字符主要包括如下 '\f' '\n' '\r' '