资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

c语言文件函数整理 c语言文件函数所有类型

C语言文件函数

//要另外说下如fprintf(stderr, "Can't open %s\n", file_app);这是向文件或者系统设备输出的函数;但他的文件指针为stderr;这是c中的标准错误输出设备指针,系统自动分配为显示器故相当于printf("Can't open %s\n", file_app);

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:主机域名、网页空间、营销软件、网站建设、邱县网站维护、网站推广。

#include stdio.h

#include stdlib.h

#include string.h

#define BUFSIZE 1024

#define SLEN 81

void append(FILE *source, FILE *dest);

int main(void)

{

FILE *fa, *fs; //定义2个文件类型指针

int files = 0; // 追加文件个数

char file_app[SLEN];

char file_src[SLEN]; // 2个字符串用来储存文件名;

puts("Enter name of destination file:");//输出Enter name of destination file:

gets(file_app);//输入要追加的文件名

if ((fa = fopen(file_app, "a")) == NULL)//fa指向追加的目的文件,以追加方式打开文件,如果打开失败退出;

{

fprintf(stderr, "Can't open %s\n", file_app);

exit(2);

}

if (setvbuf(fa, NULL, _IOFBF, BUFSIZE) != 0)//创建缓冲器与流相关,大小为BUFSIZE,作用是提高IO速度;如果打开失败退出

{

fputs("Can't create output buffer\n", stderr);

exit(3);

}

puts("Enter name of first source file (empty line to quit):");//输出Enter name of first source file (empty line to quit):

while (gets(file_src) file_src[0] != '\0')//输入源文件如果是空串结束循环

{

if (strcmp(file_src, file_app) == 0)//如果源和追加文件相同

fputs("Can't append file to itself\n",stderr);

else if ((fs = fopen(file_src, "r")) == NULL)//如果打开源文件失败

fprintf(stderr, "Can't open %s\n", file_src);

else

{

if (setvbuf(fs, NULL, _IOFBF, BUFSIZE) != 0)//创建缓冲器与流相关,大小为BUFSIZE,作用是提高IO速度;如果打开失败开始下次循环

{

fputs("Can't create input buffer\n",stderr);

continue;

}

append(fs, fa);//函数

if (ferror(fs) != 0)//检查文件操作是否有错

fprintf(stderr,"Error in reading file %s.\n",

file_src);

if (ferror(fa) != 0)

fprintf(stderr,"Error in writing file %s.\n",

file_app);

fclose(fs);//关闭源文件

files++;//追加文件数+1

printf("File %s appended.\n", file_src);

puts("Next file (empty line to quit):");

}

}

printf("Done. %d files appended.\n", files);

fclose(fa);//关闭追加文件

return 0;

}

void append(FILE *source, FILE *dest)

{

size_t bytes;

static char temp[BUFSIZE];

while ((bytes = fread(temp,sizeof(char),BUFSIZE,source)) 0)//把源文件的内容追加到追加文件,块大小sizeof(char),块数为BUFSIZE

fwrite(temp, sizeof (char), bytes, dest);//写文件块大小sizeof(char),块数为BUFSIZE

}

C语言最文件操作函数(2)

14.freopen(打开文件)

相关函数 fopen,fclose

表头文件 #includestdio.h

定义函数 FILE * freopen(const char * path,const char * mode,FILE * stream);

函数说明 参数path字符串包含欲打开的文件路径及文件名,参数mode请参考fopen()说明。参数stream为已打开的文件指针。Freopen()会将原stream所打开的文件流关闭,然后打开参数path的文件。

返回值 文件顺利打开后,指向该流的文件指针就会被返回。如果文件打开失败则返回NULL,并把错误代码存在errno 中。

范例

复制代码代码如下:

#includestdio.h

main()

{

FILE * fp;

fp=fopen(“/etc/passwd”,”r”);

fp=freopen(“/etc/group”,”r”,fp);

fclose(fp);

}

15.fseek(移动文件流的读写位置)

相关函数 rewind,ftell,fgetpos,fsetpos,lseek

表头文件 #includestdio.h

定义函数 int fseek(FILE * stream,long offset,int whence);

函数说明 fseek()用来移动文件流的读写位置。参数stream为已打开的文件指针,参数offset为根据参数whence来移动读写位置的位移数。

参数 whence为下列其中一种:

SEEK_SET从距文件开头offset位移量为新的读写位置。SEEK_CUR 以目前的读写位置往后增加offset个位移量。

SEEK_END将读写位置指向文件尾后再增加offset个位移量。

当whence值为SEEK_CUR 或SEEK_END时,参数offset允许负值的出现。

下列是较特别的使用方式:

1) 欲将读写位置移动到文件开头时:fseek(FILE *stream,0,SEEK_SET);

2) 欲将读写位置移动到文件尾时:fseek(FILE *stream,0,0SEEK_END);

返回值 当调用成功时则返回0,若有错误则返回-1,errno会存放错误代码。

附加说明 fseek()不像lseek()会返回读写位置,因此必须使用ftell()来取得目前读写的位置。

范例

复制代码代码如下:

#includestdio.h

main()

{

FILE * stream;

long offset;

fpos_t pos;

stream=fopen(“/etc/passwd”,”r”);

fseek(stream,5,SEEK_SET);

printf(“offset=%d/n”,ftell(stream));

rewind(stream);

fgetpos(stream,pos);

printf(“offset=%d/n”,pos);

pos=10;

fsetpos(stream,pos);

printf(“offset = %d/n”,ftell(stream));

fclose(stream);

}

执行 offset = 5

offset =0

offset=10

16.ftell(取得文件流的读取位置)

相关函数 fseek,rewind,fgetpos,fsetpos

表头文件 #includestdio.h

定义函数 long ftell(FILE * stream);

函数说明 ftell()用来取得文件流目前的读写位置。参数stream为已打开的文件指针。

返回值 当调用成功时则返回目前的读写位置,若有错误则返回-1,errno会存放错误代码。

错误代码 EBADF 参数stream无效或可移动读写位置的文件流。

范例 参考fseek()。

17.fwrite(将数据写至文件流)

相关函数 fopen,fread,fseek,fscanf

表头文件 #includestdio.h

定义函数 size_t fwrite(const void * ptr,size_t size,size_t nmemb,FILE * stream);

函数说明 fwrite()用来将数据写入文件流中。参数stream为已打开的文件指针,参数ptr 指向欲写入的数据地址,总共写入的字符数以参数size*nmemb来决定。Fwrite()会返回实际写入的nmemb数目。

返回值 返回实际写入的nmemb数目。

范例

复制代码代码如下:

#includestdio.h

#define set_s (x,y) {strcoy(s[x].name,y);s[x].size=strlen(y);}

#define nmemb 3

struct test

{

char name[20];

int size;

}s[nmemb];

main()

{

FILE * stream;

set_s(0,”Linux!”);

set_s(1,”FreeBSD!”);

set_s(2,”Windows2000.”);

stream=fopen(“/tmp/fwrite”,”w”);

fwrite(s,sizeof(struct test),nmemb,stream);

fclose(stream);

}

执行 参考fread()。

18.getc(由文件中读取一个字符)

相关函数 read,fopen,fread,fgetc

表头文件 #includestdio.h

定义函数 int getc(FILE * stream);

函数说明 getc()用来从参数stream所指的文件中读取一个字符。若读到文件尾而无数据时便返回EOF。虽然getc()与fgetc()作用相同,但getc()为宏定义,非真正的函数调用。

返回值 getc()会返回读取到的字符,若返回EOF则表示到了文件尾。

范例 参考fgetc()。

19.getchar(由标准输入设备内读进一字符)

相关函数 fopen,fread,fscanf,getc

表头文件 #includestdio.h

定义函数 int getchar(void);

函数说明 getchar()用来从标准输入设备中读取一个字符。然后将该字符从unsigned char转换成int后返回。

返回值 getchar()会返回读取到的字符,若返回EOF则表示有错误发生。

附加说明 getchar()非真正函数,而是getc(stdin)宏定义。

范例

复制代码代码如下:

#includestdio.h

main()

{

FILE * fp;

int c,i;

for(i=0li5;i++)

{

c=getchar();

putchar(c);

}

}

执行 1234 /*输入*/

1234 /*输出*/

20.gets(由标准输入设备内读进一字符串)

相关函数 fopen,fread,fscanf,fgets

表头文件 #includestdio.h

定义函数 char * gets(char *s);

函数说明 gets()用来从标准设备读入字符并存到参数s所指的内存空间,直到出现换行字符或读到文件尾为止,最后加上NULL作为字符串结束。

返回值 gets()若成功则返回s指针,返回NULL则表示有错误发生。

附加说明 由于gets()无法知道字符串s的大小,必须遇到换行字符或文件尾才会结束输入,因此容易造成缓冲溢出的安全性问题。建议使用fgets()取代。

范例 参考fgets()

21.mktemp(产生唯一的临时文件名)

相关函数 tmpfile

表头文件 #includestdlib.h

定义函数 char * mktemp(char * template);

函数说明 mktemp()用来产生唯一的临时文件名。参数template所指的文件名称字符串中最后六个字符必须是XXXXXX。产生后的文件名会借字符串指针返回。

返回值 文件顺利打开后,指向该流的文件指针就会被返回。如果文件打开失败则返回NULL,并把错误代码存在errno中。

附加说明 参数template所指的文件名称字符串必须声明为数组,如:

char template[ ]=”template-XXXXXX”;

不可用char * template=”template-XXXXXX”;

范例

复制代码代码如下:

#includestdlib.h

main()

{

char template[ ]=”template-XXXXXX”;

mktemp(template);

printf(“template=%s/n”,template);

}

22.putc(将一指定字符写入文件中)

相关函数 fopen,fwrite,fscanf,fputc

表头文件 #includestdio.h

定义函数 int putc(int c,FILE * stream);

函数说明 putc()会将参数c转为unsigned char后写入参数stream指定的文件中。虽然putc()与fputc()作用相同,但putc()为宏定义,非真正的函数调用。

返回值 putc()会返回写入成功的字符,即参数c。若返回EOF则代表写入失败。

范例 参考fputc()。

23.putchar(将指定的字符写到标准输出设备)

相关函数 fopen,fwrite,fscanf,fputc

表头文件 #includestdio.h

定义函数 int putchar (int c);

函数说明 putchar()用来将参数c字符写到标准输出设备。

返回值 putchar()会返回输出成功的字符,即参数c。若返回EOF则代表输出失败。

附加说明 putchar()非真正函数,而是putc(c,stdout)宏定义。

范例 参考getchar()。

24.rewind(重设文件流的读写位置为文件开头)

相关函数 fseek,ftell,fgetpos,fsetpos

表头文件 #includestdio.h

定义函数 void rewind(FILE * stream);

函数说明 rewind()用来把文件流的读写位置移至文件开头。参数stream为已打开的文件指针。此函数相当于调用fseek(stream,0,SEEK_SET)。

返回值

范例 参考fseek()

25.setbuf(设置文件流的缓冲区)

相关函数 setbuffer,setlinebuf,setvbuf

表头文件 #includestdio.h

定义函数 void setbuf(FILE * stream,char * buf);

函数说明 在打开文件流后,读取内容之前,调用setbuf()可以用来设置文件流的缓冲区。参数stream为指定的文件流,参数buf指向自定的缓冲区起始地址。如果参数buf为NULL指针,则为无缓冲IO。Setbuf()相当于调用:setvbuf(stream,buf,buf?_IOFBF:_IONBF,BUFSIZ)

返回值

26.setbuffer(设置文件流的缓冲区)

相关函数 setlinebuf,setbuf,setvbuf

表头文件 #includestdio.h

定义函数 void setbuffer(FILE * stream,char * buf,size_t size);

函数说明 在打开文件流后,读取内容之前,调用setbuffer()可用来设置文件流的缓冲区。参数stream为指定的文件流,参数buf指向自定的缓冲区起始地址,参数size为缓冲区大小。

返回值

27.setlinebuf(设置文件流为线性缓冲区)

相关函数 setbuffer,setbuf,setvbuf

表头文件 #includestdio.h

定义函数 void setlinebuf(FILE * stream);

函数说明 setlinebuf()用来设置文件流以换行为依据的无缓冲IO。相当于调用:setvbuf(stream,(char * )NULL,_IOLBF,0);请参考setvbuf()。

返回值

28.setvbuf(设置文件流的缓冲区)

相关函数 setbuffer,setlinebuf,setbuf

表头文件 #includestdio.h

定义函数 int setvbuf(FILE * stream,char * buf,int mode,size_t size);

函数说明 在打开文件流后,读取内容之前,调用setvbuf()可以用来设置文件流的缓冲区。参数stream为指定的文件流,参数buf指向自定的缓冲区起始地址,参数size为缓冲区大小,参数mode有下列几种

_IONBF 无缓冲IO

_IOLBF 以换行为依据的无缓冲IO

_IOFBF 完全无缓冲IO。如果参数buf为NULL指针,则为无缓冲IO。

返回值

29.ungetc(将指定字符写回文件流中)

相关函数 fputc,getchar,getc

表头文件 #includestdio.h

定义函数 int ungetc(int c,FILE * stream);

函数说明 ungetc()将参数c字符写回参数stream所指定的文件流。这个写回的字符会由下一个读取文件流的函数取得。

返回值 成功则返回c 字符,若有错误则返回EOF。

复制代码代码如下:

#include stdio.h

#include stdlib.h

int main()

{

FILE *fp = NULL;

char* str;

char re;

int num = 10;

str = (char*)malloc(100);

//snprintf(str, 10,"test: %s", "0123456789012345678");

// printf("str=%s\n", str);

fp = fopen("/local/test.c","a+");

if (fp==NULL){

printf("Fail to open file\n");

}

//     fseek(fp,-1,SEEK_END);

num = ftell(fp);

printf("test file long:%d\n",num);

fscanf(fp,"%s",str);

printf("str = %s\n",str);

printf("test a: %s\n",str);

while ((re=getc(fp))!=EOF){//getc可以用作fgetc用

printf("%c",re);

}

//fread(str,10,10,fp);

fgets(str,100,fp);

printf("test a: %s\n",str);

sprintf(str,"xiewei test is:%s", "ABCDEFGHIGKMNI");

printf("str2=%s\n", str);

//  fprintf(fp,"%s\n",str);

fwrite(str,2,10,fp);

num = ftell(fp);

if(str!=NULL){

free(str);

}

fclose(fp);

return 0;

}

C语言中几个文件操作函数的解释(要自己说的通俗点的)

#include stdio.h

FILE *stream;

void main( void )

{

long l;

float fp;

char s[81];

char c;

stream = fopen( "fscanf.out", "w+" );

if( stream == NULL )

printf( "The file fscanf.out was not opened\n" );

else

{

fprintf( stream, "%s %ld %f%c", "a-string",

65000, 3.14159, 'x' );

/* Set pointer to beginning of file: */

fseek( stream, 0L, SEEK_SET );

/* Read data back from file: */

fscanf( stream, "%s", s );

fscanf( stream, "%ld", l );

fscanf( stream, "%f", fp );

fscanf( stream, "%c", c );

/* Output data read: */

printf( "%s\n", s );

printf( "%ld\n", l );

printf( "%f\n", fp );

printf( "%c\n", c );

fclose( stream );

}

}

看了MSDN上的这个例子应该会用fprintf和fscanf了吧

其它的函数在MSDN上基本上都有例子参考的.

我需要c语言每个头文件里的所有函数介绍及用法!

分类函数,所在函数库为ctype.h

int isalpha(int ch) 若ch是字母('A'-'Z','a'-'z')返回非0值,否则返回0

int isalnum(int ch) 若ch是字母('A'-'Z','a'-'z')或数字('0'-'9')

返回非0值,否则返回0

int isascii(int ch) 若ch是字符(ASCII码中的0-127)返回非0值,否则返回0

int iscntrl(int ch) 若ch是作废字符(0x7F)或普通控制字符(0x00-0x1F)

返回非0值,否则返回0

int isdigit(int ch) 若ch是数字('0'-'9')返回非0值,否则返回0

int isgraph(int ch) 若ch是可打印字符(不含空格)(0x21-0x7E)返回非0值,否则返回0

int islower(int ch) 若ch是小写字母('a'-'z')返回非0值,否则返回0

int isprint(int ch) 若ch是可打印字符(含空格)(0x20-0x7E)返回非0值,否则返回0

int ispunct(int ch) 若ch是标点字符(0x00-0x1F)返回非0值,否则返回0

int isspace(int ch) 若ch是空格(' '),水平制表符('\t'),回车符('\r'),

走纸换行('\f'),垂直制表符('\v'),换行符('\n')

返回非0值,否则返回0

int isupper(int ch) 若ch是大写字母('A'-'Z')返回非0值,否则返回0

int isxdigit(int ch) 若ch是16进制数('0'-'9','A'-'F','a'-'f')返回非0值,

否则返回0

int tolower(int ch) 若ch是大写字母('A'-'Z')返回相应的小写字母('a'-'z')

int toupper(int ch) 若ch是小写字母('a'-'z')返回相应的大写字母('A'-'Z')

数学函数,所在函数库为math.h、stdlib.h、string.h、float.h

int abs(int i) 返回整型参数i的绝对值

double cabs(struct complex znum) 返回复数znum的绝对值

double fabs(double x) 返回双精度参数x的绝对值

long labs(long n) 返回长整型参数n的绝对值

double exp(double x) 返回指数函数ex的值

double frexp(double value,int *eptr) 返回value=x*2n中x的值,n存贮在eptr中

double ldexp(double value,int exp); 返回value*2exp的值

double log(double x) 返回logex的值

double log10(double x) 返回log10x的值

double pow(double x,double y) 返回xy的值

double pow10(int p) 返回10p的值

double sqrt(double x) 返回+√x的值

double acos(double x) 返回x的反余弦cos-1(x)值,x为弧度

double asin(double x) 返回x的反正弦sin-1(x)值,x为弧度

double atan(double x) 返回x的反正切tan-1(x)值,x为弧度

double atan2(double y,double x) 返回y/x的反正切tan-1(x)值,y的x为弧度

double cos(double x) 返回x的余弦cos(x)值,x为弧度

double sin(double x) 返回x的正弦sin(x)值,x为弧度

double tan(double x) 返回x的正切tan(x)值,x为弧度

double cosh(double x) 返回x的双曲余弦cosh(x)值,x为弧度

double sinh(double x) 返回x的双曲正弦sinh(x)值,x为弧度

double tanh(double x) 返回x的双曲正切tanh(x)值,x为弧度

double hypot(double x,double y) 返回直角三角形斜边的长度(z),

x和y为直角边的长度,z2=x2+y2

double ceil(double x) 返回不小于x的最小整数

double floor(double x) 返回不大于x的最大整数

void srand(unsigned seed) 初始化随机数发生器

int rand() 产生一个随机数并返回这个数

double poly(double x,int n,double c[])从参数产生一个多项式

double modf(double value,double *iptr)将双精度数value分解成尾数和阶

double fmod(double x,double y) 返回x/y的余数

double frexp(double value,int *eptr) 将双精度数value分成尾数和阶

double atof(char *nptr) 将字符串nptr转换成浮点数并返回这个浮点数

double atoi(char *nptr) 将字符串nptr转换成整数并返回这个整数

double atol(char *nptr) 将字符串nptr转换成长整数并返回这个整数

char *ecvt(double value,int ndigit,int *decpt,int *sign)

将浮点数value转换成字符串并返回该字符串

char *fcvt(double value,int ndigit,int *decpt,int *sign)

将浮点数value转换成字符串并返回该字符串

char *gcvt(double value,int ndigit,char *buf)

将数value转换成字符串并存于buf中,并返回buf的指针

char *ultoa(unsigned long value,char *string,int radix)

将无符号整型数value转换成字符串并返回该字符串,radix为转换时所用基数

char *ltoa(long value,char *string,int radix)

将长整型数value转换成字符串并返回该字符串,radix为转换时所用基数

char *itoa(int value,char *string,int radix)

将整数value转换成字符串存入string,radix为转换时所用基数

double atof(char *nptr) 将字符串nptr转换成双精度数,并返回这个数,错误返回0

int atoi(char *nptr) 将字符串nptr转换成整型数, 并返回这个数,错误返回0

long atol(char *nptr) 将字符串nptr转换成长整型数,并返回这个数,错误返回0

double strtod(char *str,char **endptr)将字符串str转换成双精度数,并返回这个数,

long strtol(char *str,char **endptr,int base)将字符串str转换成长整型数,

并返回这个数,

int matherr(struct exception *e)

用户修改数学错误返回信息函数(没有必要使用)

double _matherr(_mexcep why,char *fun,double *arg1p,

double *arg2p,double retval)

用户修改数学错误返回信息函数(没有必要使用)

unsigned int _clear87() 清除浮点状态字并返回原来的浮点状态

void _fpreset() 重新初使化浮点数学程序包

unsigned int _status87() 返回浮点状态字

int chdir(char *path) 使指定的目录path(如:"C:\\WPS")变成当前的工作目录,成

功返回0

int findfirst(char *pathname,struct ffblk *ffblk,int attrib)查找指定的文件,成功

返回0

pathname为指定的目录名和文件名,如"C:\\WPS\\TXT"

ffblk为指定的保存文件信息的一个结构,定义如下:

┏━━━━━━━━━━━━━━━━━━━━┓

┃struct ffblk ┃

┃{ ┃

┃ char ff_reserved[21]; /*DOS保留字*/ ┃

┃ char ff_attrib; /*文件属性*/ ┃

┃ int ff_ftime; /*文件时间*/ ┃

┃ int ff_fdate; /*文件日期*/ ┃

┃ long ff_fsize; /*文件长度*/ ┃

┃ char ff_name[13]; /*文件名*/ ┃

┃} ┃

┗━━━━━━━━━━━━━━━━━━━━━┛

attrib为文件属性,由以下字符代表

┏━━━━━━━━━┳━━━━━━━━━┓

┃FA_RDONLY 只读文件┃FA_LABEL 卷标号 ┃

┃FA_HIDDEN 隐藏文件┃FA_DIREC 目录 ┃

┃FA_SYSTEM 系统文件┃FA_ARCH 档案 ┃

┗━━━━━━━━━┻━━━━━━━━━┛

例:

struct ffblk ff;

findfirst("*.wps",ff,FA_RDONLY);

int findnext(struct ffblk *ffblk) 取匹配finddirst的文件,成功返回0

void fumerge(char *path,char *drive,char *dir,char *name,char *ext)

此函数通过盘符drive(C:、A:等),路径dir(\TC、\BC\LIB等),

文件名name(TC、WPS等),扩展名ext(.EXE、.COM等)组成一个文件名

存与path中.

int fnsplit(char *path,char *drive,char *dir,char *name,char *ext)

此函数将文件名path分解成盘符drive(C:、A:等),路径dir(\TC、\BC\LIB等),

文件名name(TC、WPS等),扩展名ext(.EXE、.COM等),并分别存入相应的变量中.

int getcurdir(int drive,char *direc) 此函数返回指定驱动器的当前工作目录名称

drive 指定的驱动器(0=当前,1=A,2=B,3=C等)

direc 保存指定驱动器当前工作路径的变量 成功返回0

char *getcwd(char *buf,iint n) 此函数取当前工作目录并存入buf中,直到n个字

节长为为止.错误返回NULL

int getdisk() 取当前正在使用的驱动器,返回一个整数(0=A,1=B,2=C等)

int setdisk(int drive) 设置要使用的驱动器drive(0=A,1=B,2=C等),

返回可使用驱动器总数

int mkdir(char *pathname) 建立一个新的目录pathname,成功返回0

int rmdir(char *pathname) 删除一个目录pathname,成功返回0

char *mktemp(char *template) 构造一个当前目录上没有的文件名并存于template中

char *searchpath(char *pathname) 利用MSDOS找出文件filename所在路径,

,此函数使用DOS的PATH变量,未找到文件返回NULL

进程函数,所在函数库为stdlib.h、process.h

void abort() 此函数通过调用具有出口代码3的_exit写一个终止信息于stderr,

并异常终止程序。无返回值

int exec…装入和运行其它程序

int execl( char *pathname,char *arg0,char *arg1,…,char *argn,NULL)

int execle( char *pathname,char *arg0,char *arg1,…,

char *argn,NULL,char *envp[])

int execlp( char *pathname,char *arg0,char *arg1,…,NULL)

int execlpe(char *pathname,char *arg0,char *arg1,…,NULL,char *envp[])

int execv( char *pathname,char *argv[])

int execve( char *pathname,char *argv[],char *envp[])

int execvp( char *pathname,char *argv[])

int execvpe(char *pathname,char *argv[],char *envp[])

exec函数族装入并运行程序pathname,并将参数

arg0(arg1,arg2,argv[],envp[])传递给子程序,出错返回-1

在exec函数族中,后缀l、v、p、e添加到exec后,

所指定的函数将具有某种操作能力

有后缀 p时,函数可以利用DOS的PATH变量查找子程序文件。

l时,函数中被传递的参数个数固定。

v时,函数中被传递的参数个数不固定。

e时,函数传递指定参数envp,允许改变子进程的环境,

无后缀e时,子进程使用当前程序的环境。

void _exit(int status)终止当前程序,但不清理现场

void exit(int status) 终止当前程序,关闭所有文件,写缓冲区的输出(等待输出),

并调用任何寄存器的"出口函数",无返回值

int spawn…运行子程序

int spawnl( int mode,char *pathname,char *arg0,char *arg1,…,

char *argn,NULL)

int spawnle( int mode,char *pathname,char *arg0,char *arg1,…,

char *argn,NULL,char *envp[])

int spawnlp( int mode,char *pathname,char *arg0,char *arg1,…,

char *argn,NULL)

int spawnlpe(int mode,char *pathname,char *arg0,char *arg1,…,

char *argn,NULL,char *envp[])

int spawnv( int mode,char *pathname,char *argv[])

int spawnve( int mode,char *pathname,char *argv[],char *envp[])

int spawnvp( int mode,char *pathname,char *argv[])

int spawnvpe(int mode,char *pathname,char *argv[],char *envp[])

spawn函数族在mode模式下运行子程序pathname,并将参数

arg0(arg1,arg2,argv[],envp[])传递给子程序.出错返回-1

mode为运行模式

mode为 P_WAIT 表示在子程序运行完后返回本程序

P_NOWAIT 表示在子程序运行时同时运行本程序(不可用)

P_OVERLAY表示在本程序退出后运行子程序

在spawn函数族中,后缀l、v、p、e添加到spawn后,

所指定的函数将具有某种操作能力

有后缀 p时, 函数利用DOS的PATH查找子程序文件

l时, 函数传递的参数个数固定.

v时, 函数传递的参数个数不固定.

e时, 指定参数envp可以传递给子程序,允许改变子程序运行环境.

当无后缀e时,子程序使用本程序的环境.

int system(char *command) 将MSDOS命令command传递给DOS执行

转换子程序,函数库为math.h、stdlib.h、ctype.h、float.h

char *ecvt(double value,int ndigit,int *decpt,int *sign)

将浮点数value转换成字符串并返回该字符串

char *fcvt(double value,int ndigit,int *decpt,int *sign)

将浮点数value转换成字符串并返回该字符串

char *gcvt(double value,int ndigit,char *buf)

将数value转换成字符串并存于buf中,并返回buf的指针

char *ultoa(unsigned long value,char *string,int radix)

将无符号整型数value转换成字符串并返回该字符串,radix为转换时所用基数

char *ltoa(long value,char *string,int radix)

将长整型数value转换成字符串并返回该字符串,radix为转换时所用基数

char *itoa(int value,char *string,int radix)

将整数value转换成字符串存入string,radix为转换时所用基数

double atof(char *nptr) 将字符串nptr转换成双精度数,并返回这个数,错误返回0

int atoi(char *nptr) 将字符串nptr转换成整型数, 并返回这个数,错误返回0

long atol(char *nptr) 将字符串nptr转换成长整型数,并返回这个数,错误返回0

double strtod(char *str,char **endptr)将字符串str转换成双精度数,并返回这个数,

long strtol(char *str,char **endptr,int base)将字符串str转换成长整型数,

并返回这个数,

int toascii(int c) 返回c相应的ASCII

int tolower(int ch) 若ch是大写字母('A'-'Z')返回相应的小写字母('a'-'z')

int _tolower(int ch) 返回ch相应的小写字母('a'-'z')

int toupper(int ch) 若ch是小写字母('a'-'z')返回相应的大写字母('A'-'Z')

int _toupper(int ch) 返回ch相应的大写字母('A'-'Z')

诊断函数,所在函数库为assert.h、math.h

void assert(int test) 一个扩展成if语句那样的宏,如果test测试失败,

就显示一个信息并异常终止程序,无返回值

void perror(char *string) 本函数将显示最近一次的错误信息,格式如下:

字符串string:错误信息

char *strerror(char *str) 本函数返回最近一次的错误信息,格式如下:

字符串str:错误信息

int matherr(struct exception *e)

用户修改数学错误返回信息函数(没有必要使用)

double _matherr(_mexcep why,char *fun,double *arg1p,

double *arg2p,double retval)

用户修改数学错误返回信息函数(没有必要使用)


分享文章:c语言文件函数整理 c语言文件函数所有类型
当前URL:http://cdkjz.cn/article/ddohcdp.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220