Ⅰ c語言中的標准函數有哪些
C語言輸入輸出函數有很多,標准I/O函數中包含了如下幾個常用的函數:
scanf,printf,getc,putc,getchar,putchar,gets,puts,fgets,fputs,fgetc,fputc,fscanf,fprintf等.
int getc(FILE *fp)
getc主要是從文件中讀出一個字元.常用的判斷文件是否讀取結束的語句為 (ch = getc(fp)) != EOF.EOF為文件結束標志,定義在stdio.h中,就像EXIT_SUCCESS,EXIT_FAILURE定義在stdlib.h中一樣,文件也可以被理解為一種流,所以當fp為stdin時,getc(stdin)就等同於getchar()了.
int putc(int ch,FILE *fp)
putc主要是把字元ch寫到文件fp中去.如果fp為stdout,則putc就等同於putchar()了.
int getchar(void)
getchar主要是從標准輸入流讀取一個字元.默認的標准輸入流即stdio.h中定義的stdin.但是從輸入流中讀取字元時又涉及到緩沖的問題,所以並不是在屏幕中敲上一個字元程序就會運行,一般是通過在屏幕上敲上回車鍵,然後將回車前的字元串放在緩沖區中,getchar就是在緩沖區中一個一個的讀字元.當然也可以在while循環中指定終止字元,如下面的語句:while ((c = getchar()) != '#')這是以#來結束的.
int putchar(int ch)
putchar(ch)主要是把字元ch寫到標准流stdout中去.
char * gets(char *str)
gets主要是從標准輸入流讀取字元串並回顯,讀到換行符時退出,並會將換行符省去.
int puts(char *str)
puts主要是把字元串str寫到標准流stdout中去,並會在輸出到最後時添加一個換行符.
char *fgets(char *str, int num, FILE *fp)
str是存放讀入的字元數組指針,num是最大允許的讀入字元數,fp是文件指針.fgets的功能是讀一行字元,該行的字元數不大於num-1.因為fgets函數會在末尾加上一個空字元以構成一個字元串.另外fgets在讀取到換行符後不會將其省略.
int fputs(char *str, file *fp)
fputs將str寫入fp.fputs與puts的不同之處是fputs在列印時並不添加換行符.
int fgetc(FILE *fp)
fgetc從fp的當前位置讀取一個字元.
int fputc(int ch, file *fp)
fputc是將ch寫入fp當前指定位置.
int fscanf(FILE *fp, char *format, 輸入列表)
fscanf按照指定格式從文件中出讀出數據,並賦值到參數列表中.
int fprintf(FILE *fp, char *format, 輸出列表)
fprintf將格式化數據寫入流式文件中.
數據塊讀寫函數
fread (buffer,size,count,fp);
fwrite(buffer,size,count,fp);
參數說明:
buffer:是一個指針。
對fread 來說,它是讀入數據的存放地址。
對fwrite來說,是要輸出數據的地址(均指起始地址)。
size: 要讀寫的位元組數。
count: 要進行讀寫多少個size位元組的數據項。
fp: 文件型指針。
Ⅱ 我需要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語言中頭文件及函數的含意的總分類
ALLOC.H 說明內存管理函數(分配、釋放等)。
ASSERT.H 定義 assert調試宏。
BIOS.H 說明調用IBM—PC ROM BIOS子程序的各個函數。
CONIO.H 說明調用DOS控制台I/O子程序的各個函數。
CTYPE.H 包含有關字元分類及轉換的名類信息(如 isalpha和toascii等)。
DIR.H 包含有關目錄和路徑的結構、宏定義和函數。
DOS.H 定義和說明MSDOS和8086調用的一些常量和函數。
ERRON.H 定義錯誤代碼的助記符。
FCNTL.H 定義在與open庫子程序連接時的符號常量。
FLOAT.H 包含有關浮點運算的一些參數和函數。
GRAPHICS.H 說明有關圖形功能的各個函數,圖形錯誤代碼的常量定義,正對不同驅動程序的各種顏色值,及函數用到的一些特殊結構。
IO.H 包含低級I/O子程序的結構和說明。
LIMIT.H 包含各環境參數、編譯時間限制、數的范圍等信息。
MATH.H 說明數學運算函數,還定了 HUGE VAL 宏, 說明了matherr和matherr子程序用到的特殊結構。
MEM.H 說明一些內存操作函數(其中大多數也在STRING.H 中說明)。
PROCESS.H 說明進程管理的各個函數,spawn…和EXEC …函數的結構說明。
SETJMP.H 定義longjmp和setjmp函數用到的jmp buf類型, 說明這兩個函數。
SHARE.H 定義文件共享函數的參數。
SIGNAL.H 定義SIG[ZZ(Z] [ZZ)]IGN和SIG[ZZ(Z] [ZZ)]DFL常量,說明rajse和signal兩個函數。
STDARG.H 定義讀函數參數表的宏。(如vprintf,vscarf函數)。
STDDEF.H 定義一些公共數據類型和宏。
STDIO.H 定義Kernighan和Ritchie在Unix System V 中定義的標准和擴展的類型和宏。還定義標准I/O 預定義流:stdin,stdout和stderr,說明 I/O流子程序。
STDLIB.H 說明一些常用的子程序:轉換子程序、搜索/ 排序子程序等。
STRING.H 說明一些串操作和內存操作函數。
SYS\STAT.H 定義在打開和創建文件時用到的一些符號常量。
SYS\TYPES.H 說明ftime函數和timeb結構。
SYS\TIME.H 定義時間的類型time[ZZ(Z] [ZZ)]t。
TIME.H 定義時間轉換子程序asctime、localtime和gmtime的結構,ctime、 difftime、 gmtime、 localtime和stime用到的類型,並提供這些函數的原型。
VALUE.H 定義一些重要常量, 包括依賴於機器硬體的和為與Unix System V相兼容而說明的一些常量,包括浮點和雙精
分類函數,所在函數庫為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() 返回浮點狀態字
目錄函數,所在函數庫為dir.h、dos.h
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語言中modf函數的具體用法,包括那個地方寫那變數,例如求變數n的小數部分。
modf 函數名: modf
功 能: 把數分為整數和小數 (The modf function breaks down the floating-point value x into fractional and integer parts, each of which has the same sign as x. The signed fractional portion of x is returned. The integer portion is stored as a floating-point value at intptr.
)
用 法: double modf(double x, double *intptr);
程序例:
#include <math.h>
#include <stdio.h>
int main(void)
{
double fraction, integer;
double number = 100000.567;
fraction = modf(number, &integer);
printf("The whole and fractional parts of %lf are %lf and %lf\n",
number, integer, fraction);
return 0;
}
Ⅳ C語言中各種函數的具體作用,要詳細點的
字元處理函數
本類別函數用於對單個字元進行處理,包括字元的類別測試和字元的大小寫轉換
頭文件 ctype.h
函數列表<>
函數類別 函數用途 詳細說明
字元測試 是否字母和數字 isalnum
是否字母 isalpha
是否控制字元 iscntrl
是否數字 isdigit
是否可顯示字元(除空格外) isgraph
是否可顯示字元(包括空格) isprint
是否既不是空格,又不是字母和數字的可顯示字元 ispunct
是否空格 isspace
是否大寫字母 isupper
是否16進制數字(0-9,A-F)字元 isxdigit
字元大小寫轉換函數 轉換為大寫字母 toupper
轉換為小寫字母 tolower
地區化
本類別的函數用於處理不同國家的語言差異。
頭文件 local.h
函數列表
函數類別 函數用途 詳細說明
地區控制 地區設置 setlocale
數字格式約定查詢 國家的貨幣、日期、時間等的格式轉換 localeconv
數學函數
本分類給出了各種數學計算函數,必須提醒的是ANSI C標准中的數據格式並不符合IEEE754標准,一些C語言編譯器卻遵循IEEE754(例如frinklin C51)
頭文件 math.h
函數列表
函數類別 函數用途 詳細說明
錯誤條件處理 定義域錯誤(函數的輸入參數值不在規定的范圍內)
值域錯誤(函數的返回值不在規定的范圍內)
三角函數 反餘弦 acos
反正弦 asin
反正切 atan
反正切2 atan2
餘弦 cos
正弦 sin
正切 tan
雙曲函數 雙曲餘弦 cosh
雙曲正弦 sinh
雙曲正切 tanh
指數和對數 指數函數 exp
指數分解函數 frexp
乘積指數函數 fdexp
自然對數 log
以10為底的對數 log10
浮點數分解函數 modf
冪函數 冪函數 pow
平方根函數 sqrt
整數截斷,絕對值和求余數函數 求下限接近整數 ceil
絕對值 fabs
求上限接近整數 floor
求余數 fmod
本分類函數用於實現在不同底函數之間直接跳轉代碼。 頭文件 setjmp.h io.h
函數列表
函數類別 函數用途 詳細說明
保存調用環境 setjmp
恢復調用環境 longjmp
信號處理
該分類函數用於處理那些在程序執行過程中發生例外的情況。
頭文件 signal.h
函數列表
函數類別 函數用途 詳細說明
指定信號處理函數 signal
發送信號 raise
可變參數處理
本類函數用於實現諸如printf,scanf等參數數量可變底函數。
頭文件 stdarg.h
函數列表
函數類別 函數用途 詳細說明
可變參數訪問宏 可變參數開始宏 va_start
可變參數結束宏 va_end
可變參數訪問宏 訪問下一個可變參數宏 va_arg
輸入輸出函數
該分類用於處理包括文件、控制台等各種輸入輸出設備,各種函數以「流」的方式實現
頭文件 stdio.h
函數列表
函數類別 函數用途 詳細說明
文件操作
刪除文件 remove
修改文件名稱 rename
生成臨時文件名稱 tmpfile
得到臨時文件路徑 tmpnam
文件訪問 關閉文件 fclose
刷新緩沖區 fflush
打開文件 fopen
將已存在的流指針和新文件連接 freopen
設置磁碟緩沖區 setbuf
設置磁碟緩沖區 setvbuf
格式化輸入與輸出函數 格式輸出 fprintf
格式輸入 fscanf
格式輸出(控制台) printf
格式輸入(控制台) scanf
格式輸出到緩沖區 sprintf
從緩沖區中按格式輸入 sscanf
格式化輸出 vfprintf
格式化輸出 vprintf
格式化輸出 vsprintf
字元輸入輸出函數 輸入一個字元 fgetc
字元串輸入 fgets
字元輸出 fputc
字元串輸出 fputs
字元輸入(控制台) getc
字元輸入(控制台) getchar
字元串輸入(控制台) gets
字元輸出(控制台) putc
字元輸出(控制台) putchar
字元串輸出(控制台) puts
字元輸出到流的頭部 ungetc
直接輸入輸出 直接流讀操作 fread
直接流寫操作 fwrite
文件定位函數 得到文件位置 fgetpos
文件位置移動 fseek
文件位置設置 fsetpos
得到文件位置 ftell
文件位置復零位 remind
錯誤處理函數 錯誤清除 clearerr
文件結尾判斷 feof
文件錯誤檢測 ferror
得到錯誤提示字元串 perror
實用工具函數
本分類給出了一些函數無法按以上分類,但又是編程所必須要的。
頭文件 stdlib.h
函數列表
函數類別 函數用途 詳細說明
字元串轉換函數 字元串轉換為整數 atoi
字元串轉換為長整數 atol
字元串轉換為浮點數 strtod
字元串轉換為長整數 strtol
字元串轉換為無符號長整型 strtoul
偽隨機序列產生函數 產生隨機數 rand
設置隨機函數的起動數值 srand
存儲管理函數 分配存儲器 calloc
釋放存儲器 free
存儲器分配 malloc
重新分配存儲器 realloc
環境通信 中止程序 abort
退出程序執行,並清除環境變數 atexit
退出程序執行 exit
讀取環境參數 getenv
程序掛起,臨時執行一個其他程序 system
搜索和排序工具 二分查找(數據必須已排序) bsearch
快速排序 qsort
整數運算函數 求絕對值 abs
div
得到除法運算底商和余數
求長整形底絕對值 labs
求長整形除法的商和余數 ldiv
多位元組字元函數 得到多位元組字元的位元組數 mblen
得到多位元組字元的位元組數 mbtowc
多位元組字元轉換 wctomb
多位元組字元的字元串操作 將多位元組串轉換為整數數組 mbstowcs
將多位元組串轉換為字元數組 mcstowbs
字元串處理
本分類的函數用於對字元串進行合並、比較等操作
頭文件 string.h
函數列表
函數類別 函數用途 詳細說明
字元串拷貝 塊拷貝(目的和源存儲區不可重疊) memcpy
塊拷貝(目的和源存儲區可重疊) memmove
串拷貝 strcpy
按長度的串拷貝 strncpy
字元串連接函數 串連接 strcat
按長度連接字元串 strncat
串比較函數 塊比較 memcmp
字元串比較 strcmp
字元串比較(用於非英文字元) strcoll
按長度對字元串比較 strncmp
字元串轉換 strxfrm
字元與字元串查找 字元查找 memchr
字元查找 strchr
字元串查找 strcspn
字元串查找 strpbrk
字元串查找 strspn
字元串查找 strstr
字元串分解 strtok
雜類函數 字元串設置 memset
錯誤字元串映射 strerror
求字元串長度 strlen
日期和時間函數
本類別給出時間和日期處理函數
頭文件 time.h
函數列表
函數類別 函數用途 詳細說明
時間操作函數 得到處理器時間 clock
得到時間差 difftime
設置時間 mktime
得到時間 time
時間轉換函數 得到以ASCII碼表示的時間 asctime
得到字元串表示的時間 ctime
得到指定格式的時間 strftime
函數庫未來的發展方向
本部分用於說明各類別函數庫在將來如何發展。
序號 庫類別 頭文件 詳細說明
1 錯誤處理 errno.h
2 字元處理 ctype.h
3 地區化 local.h
4 數學函數 math.h
5 信號處理 signal.h
6 輸入輸出 stdio.h
7 實用工具程序 stdlib.h
8 字元串處理 string.h
Ⅵ 求C語言所有的簡單函數!
庫函數並不是C語言的一部分,它是由編譯程序根據一般用戶的需要編制並提供用戶使用的一組程序。每一種C編譯系統都提供了一批庫函數,不同的編譯系統所提供的庫函數的數目和函數名以及函數功能是不完全相同的。ANSIC標准提出了一批建議提供的標准庫函數。它包括了目前多數C編譯系統所提供的庫函數,但也有一些是某些C編譯系統未曾實現的。考慮到通用性,本書列出Turbo C 2.0版提供的部分常用庫函數。
由於Turbo C庫函數的種類和數目很多(例如:還有屏幕和圖形函數、時間日期函數、與本系統有關的函數等,每一類函數又包括各種功能的函數),限於篇幅,本附錄不能全部介紹,只從教學需要的角度列出最基本的。讀者在編制c程序時可能要用到更多的函數,請查閱有關的Turbo C庫函數手冊。
(1)數學函數
使用數學函數時,應該在源文件中使用命令:
#include″math.h″
函數名 函數與形參類型 功 能 返回值
acos double acos(x)
double x 計算cos-1(x)的值
-1<=x<=1 計算結果
asin double asin(x)
double x 計算sin-1(x)的值
-1<=x<=1 計算結果
atan double atan(x)
double x 計算tan-1(x)的值 計算結果
atan2 double atan2(x,y)
double x,y 計算tan-1(x/y)的值 計算結果
cos double cos(x)
double x 計算cos(x)的值
x的單位為弧度 計算結果
cosh double cosh(x)
double x 計算x的雙曲餘弦cosh(x)的值 計算結果
exp double exp(x)
double x 求ex的值 計算結果
fabs double fabs(x)
double x 求x的絕對值 計算結果
floor double floor(x)
double x 求出不大於x的最大整數 該整數的雙精度實數
fmod double fmod(x,y)
double x,y 求整除x/y的余數 返回余數的雙精度實數
frexp double frexp(val,eptr)
double val
int *eptr 把雙精度數val分解成數字部分(尾數)和以2為底的指數,即val=x*2n,n存放在eptr指向的變數中 數字部分x
0.5<=x<1
log double log(x)
double x 求logex即lnx 計算結果
log10 double log10(x)
double x 求log10x 計算結果
modf double modf(val,iptr)
double val
int *iptr 把雙精度數val分解成數字部分和小數部分,把整數部分存放在ptr指向的變數中 val的小數部分
pow double pow(x,y)
double x,y 求xy的值 計算結果
sin double sin(x)
double x 求sin(x)的值
x的單位為弧度 計算結果
sinh double sinh(x)
double x 計算x的雙曲正弦函數sinh(x)的值 計算結果
sqrt double sqrt (x)
double x 計算√x,x≧0 計算結果
tan double tan(x)
double x 計算tan(x)的值
x的單位為弧度 計算結果
tanh double tanh(x)
double x 計算x的雙曲正切函數tanh(x)的值 計算結果
------------------------------------------------------------------------------------------------------------------------------
(2)字元函數
在使用字元函數時,因該在源文件中使用命令:
#include「ctype.h」
函數名 函數和形參類型 功能 返回值
isalnum int isalnum(ch)
int ch 檢查ch是否字母或數字 是字母或數字返回1;否則返回0
isalpha int isalpha(ch)
int ch 檢查ch是否字母 是字母返回1;否則返回0
iscntrl int iscntrl(ch)
int ch 檢查ch是否控制字元(其ASCⅡ碼在0和0xlF之間) 是控制字元返回1;否則返回0
isdigit int isdigit(ch)
int ch 檢查ch是否數字 是數字返回1;否則返回0
isgraph int isgraph(ch)
int ch 檢查ch是否是可列印字元(其ASCⅡ碼在0x21和0x7e之間),不包括空格 是可列印字元返回1;否則返回0
islower int islower(ch)
int ch 檢查ch是否是小寫字母
(a~z) 是小字母返回1;否則返回0
isprint int isprint(ch)
int ch 檢查ch是否是可列印字元(其ASCⅡ碼在0x21和0x7e之間),不包括空格 是可列印字元返回1;否則返回0
ispunct int ispunct(ch)
int ch 檢查ch是否是標點字元(不包括空格)即除字母、數字和空格以外的所有可列印字元 是標點返回1;否則返回0
isspace int isspace(ch)
int ch 檢查ch是否空格、跳格符(製表符)或換行符 是,返回1;否則返回0
issupper int isalsupper(ch)
int ch 檢查ch是否大寫字母
(A~Z) 是大寫字母返回1;否則返回0
isxdigit int isxdigit(ch)
int ch 檢查ch是否一個16進制數字
(即0~9,或A到F,a~f) 是,返回1;否則返回0
tolower int tolower(ch)
int ch 將ch字元轉換為小寫字母 返回ch對應的小寫字母
toupper int toupper(ch)
int ch 將ch字元轉換為大寫字母 返回ch對應的大寫字母
-----------------------------------------------------------------------------------------------------------------------
(3)字元串函數
使用字元串中函數時,應該在源文件中使用命令:
#include「string.h」
函數名 函數和形參類型 功能 返回值
memchr void memchr(buf,ch,count)
void *buf;charch;
unsigned int count; 在buf的前count個字元里搜索字元ch首次出現的位置 返回指向buf中ch的第一次出現的位置指針;若沒有找到ch,返回NULL
memcmp int memcmp(buf1,buf2,count)
void *buf1,*buf2;
unsigned int count; 按字典順序比較由buf1和buf2指向的數組的前count個字元 buf1<buf2,為負數
buf1=buf2,返回0
buf1>buf2,為正數
memcpy void *memcpy(to,from,count)
void *to,*from;
unsigned int count; 將from指向的數組中的前count個字元拷貝到to指向的數組中。From和to指向的數組不允許重疊 返回指向to的指針
memove void *memove(to,from,count)
void *to,*from;
unsigned int count; 將from指向的數組中的前count個字元拷貝到to指向的數組中。From和to指向的數組不允許重疊 返回指向to的指針
memset void *memset(buf,ch,count)
void *buf;char ch;
unsigned int count; 將字元ch拷貝到buf指向的數組前count個字元中。 返回buf
strcat char *strcat(str1,str2)
char *str1,*str2; 把字元str2接到str1後面,取消原來str1最後面的串結束符`\0` 返回str1
strchr char *strchr(str1,ch)
char *str;
int ch; 找出str指向的字元串中第一次出現字元ch的位置 返回指向該位置的指針,如找不到,則應返回NULL
strcmp int *strcmp(str1,str2)
char *str1,*str2; 比較字元串str1和str2 str1<str2,為負數
str1=str2,返回0
str1>str2,為正數
strcpy char *strcpy(str1,str2)
char *str1,*str2; 把str2指向的字元串拷貝到str1中去 返回str1
strlen unsigned intstrlen(str)
char *str; 統計字元串str中字元的個數(不包括終止符`\0`) 返回字元個數
strncat char *strncat(str1,str2,count)
char *str1,*str2;
unsigned int count; 把字元串str2指向的字元串中最多count個字元連到串str1後面,並以null結尾 返回str1
strncmp int strncmp(str1,str2,count)
char *str1,*str2;
unsigned int count; 比較字元串str1和str2中至多前count個字元 str1<str2,為負數
str1=str2,返回0
str1>str2,為正數
strncpy char *strncpy(str1,str2,count)
char *str1,*str2;
unsigned int count; 把str2指向的字元串中最多前count個字元拷貝到串str1中去 返回str1
strnset void *setnset(buf,ch,count)
char *buf;char ch;
unsigned int count; 將字元ch拷貝到buf指向的數組前count個字元中。 返回buf
strset void *setnset(buf,ch)
void *buf;char ch; 將buf所指向的字元串中的全部字元都變為字元ch 返回buf
strstr char *strstr(str1,str2)
char *str1,*str2; 尋找str2指向的字元串在str1指向的字元串中首次出現的位置 返回str2指向的字元串首次出向的地址。否則返回NULL
-----------------------------------------------------------------------------------------------------------------------------
(4)輸入輸出函數
在使用輸入輸出函數時,應該在源文件中使用命令:
#include「stdio.h」
函數名 函數和形參類型 功能 返回值
clearerr void clearer(fp)
FILE *fp 清除文件指針錯誤指示器 無
close int close(fp)
int fp 關閉文件(非ANSI標准) 關閉成功返回0,不成功返回-1
creat int creat(filename,mode)
char *filename;
int mode 以mode所指定的方式建立文件。(非ANSI標准) 成功返回正數,
否則返回-1
eof int eof(fp)
int fp 判斷fp所指的文件是否結束 文件結束返回1,
否則返回0
fclose int fclose(fp)
FILE *fp 關閉fp所指的文件,釋放文件緩沖區 關閉成功返回0,不成功返回非0
feof int feof(fp)
FILE *fp 檢查文件是否結束 文件結束返回非0,否則返回0
ferror int ferror(fp)
FILE *fp 測試fp所指的文件是否有錯誤 無錯返回0;
否則返回非0
fflush int fflush(fp)
FILE *fp 將fp所指的文件的全部控制信息和數據存檔 存檔正確返回0;
否則返回非0
fgets char *fgets(buf,n,fp) char *buf;int n;
FILE *fp 從fp所指的文件讀取一個長度為(n-1)的字元串,存入起始地址為buf的空間 返回地址buf;若遇文件結束或出錯則返回EOF
fgetc int fgetc(fp)
FILE *fp 從fp所指的文件中取得下一個字元 返回所得到的字元;出錯返回EOF
fopen FILE *fopen(filename,mode)
char *filename,*mode 以mode指定的方式打開名為filename的文件 成功,則返回一個文件指針;否則返回0
fprintf int fprintf(fp,format,args,…)
FILE *fp;char *format 把args的值以format指定的格式輸出到fp所指的文件中 實際輸出的字元數
fputc int fputc(ch,fp)
char ch;FILE *fp 將字元ch輸出到fp所指的文件中 成功則返回該字元;出錯返回EOF
fputs int fputs(str,fp)
char str;FILE *fp 將str指定的字元串輸出到fp所指的文件中 成功則返回0;出錯返回EOF
fread int fread(pt,size,n,fp) char *pt;unsigned size,n;FILE *fp 從fp所指定文件中讀取長度為size的n個數據項,存到pt所指向的內存區 返回所讀的數據項個數,若文件結束或出錯返回0
fscanf int fscanf(fp,format,args,…)
FILE *fp;char *format 從fp指定的文件中按給定的format格式將讀入的數據送到args所指向的內存變數中(args是指針) 以輸入的數據個數
fseek int fseek(fp,offset,base)
FILE *fp;long offset;int base 將fp指定的文件的位置指針移到base所指出的位置為基準、以offset為位移量的位置 返回當前位置;否則,返回-1
siell FILE *fp;
long ftell(fp); 返回fp所指定的文件中的讀寫位置 返迴文件中的讀寫位置;否則,返回0
fwrite int fwrite(ptr,size,n,fp) char *ptr;unsigned size,n;FILE *fp 把ptr所指向的n*size個位元組輸出到fp所指向的文件中 寫到fp文件中的數據項的個數
getc int getc(fp)
FILE *fp; 從fp所指向的文件中的讀出下一個字元 返回讀出的字元;若文件出錯或結束返回EOF
getchar int getchat() 從標准輸入設備中讀取下一個字元 返回字元;若文件出錯或結束返回-1
gets char *gets(str)
char *str 從標准輸入設備中讀取字元串存入str指向的數組 成功返回str,否則返回NULL
open int open(filename,mode) char *filename;
int mode 以mode指定的方式打開已存在的名為filename的文件
(非ANSI標准) 返迴文件號(正數);如打開失敗返回-1
printf int printf(format,args,
…)
char *format 在format指定的字元串的控制下,將輸出列表args的指輸出到標准設備 輸出字元的個數;若出錯返回負數
prtc int prtc(ch,fp)
int ch;FILE *fp; 把一個字元ch輸出到fp所值的文件中 輸出字元ch;若出錯返回EOF
putchar int putchar(ch)
char ch; 把字元ch輸出到fp標准輸出設備 返回換行符;若失敗返回EOF
puts int puts(str)
char *str; 把str指向的字元串輸出到標准輸出設備;將`\0`轉換為回車行 返回換行符;若失敗返回EOF
putw int putw(w,fp)
int i;
FILE *fp; 將一個整數i(即一個字)寫到fp所指的文件中
(非ANSI標准) 返回讀出的字元;若文件出錯或結束返回EOF
read int read(fd,buf,count) int fd;char *buf;
unsigned int count; 從文件號fp所指定文件中讀count個位元組到由buf知識的緩沖區(非ANSI標准) 返回真正讀出的位元組個數,如文件結束返回0,出錯返回-1
remove int remove(fname)
char *fname; 刪除以fname為文件名的文件 成功返回0;出錯返回-1
rename int remove(oname,nname)
char *oname,*nname; 把oname所指的文件名改為由nname所指的文件名 成功返回0;出錯返回-1
rewind void rewind(fp)
FILE *fp; 將fp指定的文件指針置於文件頭,並清除文件結束標志和錯誤標志 無
scanf int scanf(format,args,
…)
char *format 從標准輸入設備按format指示的格式字元串規定的格式,輸入數據給args所指示的單元。args為指針 讀入並賦給args數據個數。如文件結束返回EOF;若出錯返回0
write int write(fd,buf,count) int fd;char *buf;
unsigned count; 叢buf指示的緩沖區輸出count個字元到fd所指的文件中(非ANSI標准) 返回實際寫入的位元組數,如出錯返回-1
------------------------------------------------------------------------------------------------------------------------------
(5)動態存儲分配函數
在使用動態存儲分配函數時,應該在源文件中使用命令:
#include「stdlib.h」
函數名 函數和形參類型 功能 返回值
callloc void *calloc(n,size)
unsigned n;
unsigned size; 分配n個數據項的內存連續空間,每個數據項的大小為size 分配內存單元的起始地址。如不成功,返回0
free void free(p)
void *p; 釋放p所指內存區 無
malloc void *malloc(size)
unsigned SIZE; 分配size位元組的內存區 所分配的內存區地址,如內存不夠,返回0
realloc void *reallod(p,size)
void *p;
unsigned size; 將p所指的以分配的內存區的大小改為size。Size可以比原來分配的空間大或小 返回指向該內存區的指針。若重新分配失敗,返回NULL
-------------------------------------------------------------------------------------------------------------------------------
(6)其他函數
「其他函數」是C語言的標准庫函數,由於不便歸入某一類,所以單獨列出。使用這寫函數時,應該在源文件中使用命令:
#include「stdlib.h」
函數名 函數和形參類型 功能 返回值
abs int abs(num)
int num 計算整數num的絕對值 返回計算結果
atof double atof(str)
char *str 將str指向的字元串轉換為一個double型的值 返回雙精度計算結果
atoi int atoi(str)
char *str 將str指向的字元串轉換為一個int型的值 返回轉換結果
atol long atol(str)
char *str 將str指向的字元串轉換為一個long型的值 返回轉換結果
exit void exit(status)
int status; 中止程序運行。將status的值返回調用的過程 無
itoa char *itoa(n,str,radix)
int n,radix;
char *str 將整數n的值按照radix進制轉換為等價的字元串,並將結果存入str指向的字元串中 返回一個指向str的指針
labs long labs(num)
long num 計算c整數num的絕對值 返回計算結果
ltoa char *ltoa(n,str,radix)
long int n;int radix;
char *str; 將長整數n的值按照radix進制轉換為等價的字元串,並將結果存入str指向的字元串 返回一個指向str的指針
rand int rand() 產生0到RAND_MAX之間的偽隨機數。RAND_MAX在頭文件中定義 返回一個偽隨機(整)數
random int random(num)
int num; 產生0到num之間的隨機數。 返回一個隨機(整)數
rand_omize void randomize() 初始化隨機函數,使用是包括頭文件time.h。
strtod double strtod(start,end)
char *start;
char **end 將start指向的數字字元串轉換成double,直到出現不能轉換為浮點的字元為止,剩餘的字元串符給指針end
*HUGE_VAL是turboC在頭文件math.H中定義的數學函數溢出標志值 返回轉換結果。若為轉換則返回0。若轉換出錯返回HUGE_VAL表示上溢,或返回-HUGE_VAL表示下溢
strtol Long int strtol(start,end,radix)
char *start;
char **end;
int radix; 將start指向的數字字元串轉換成long,直到出現不能轉換為長整形數的字元為止,剩餘的字元串符給指針end。
轉換時,數字的進制由radix
確定。
*LONG_MAX是turboC在頭文件limits.h中定義的long型可表示的最大值 返回轉換結果。若為轉換則返回0。若轉換出錯返回LONG_MAX表示上溢,或返回-LONG_MAX表示下溢
system int system(str)
char *str; 將str指向的字元串作為命令傳遞給DOS的命令處理器 返回所執行命令的退出狀態
Ⅶ C語言中的數學符號如何表示(大全)
abs(計算整型數的絕對值)
相關函數 labs, fabs
表頭文件 #include<stdlib.h>
定義函數 int abs (int j)
函數說明 abs()用來計算參數j的絕對值,然後將結果返回。
返回值 返回參數j的絕對值結果。
範例 #ingclude <stdlib.h>
main(){
int ansert;
answer = abs(-12);
printf("|-12| = %d\n", answer);
}
執行 |-12| = 12
/*---------------------------------*/
exp(計算指數)
相關函數 log,log10,pow
表頭文件 #include<math.h>
定義函數 double exp(double x);
函數說明 exp()用來計算以e為底的x次方值,即ex值,然後將結果返回。
返回值 返回e的x次方計算結果。
附加說明 使用GCC編譯時請加入-lm。
範例 #include<math.h>
main()
{
double answer;
answer = exp (10);
printf("e^10 =%f\n", answer);
}
執行 e^10 = 22026.465795
/*-----------------------------------*/
sqrt(計算平方根值)
相關函數 hypotq
表頭文件 #include<math.h>
定義函數 double sqrt(double x);
函數說明 sqrt()用來計算參數x的平方根,然後將結果返回。參數x必須為正數。
返回值 返回參數x的平方根值。
錯誤代碼 EDOM 參數x為負數。
附加說明 使用GCC編譯時請加入-lm。
範例 /* 計算200的平方根值*/
#include<math.h>
main()
{
double root;
root = sqrt (200);
printf("answer is %f\n",root);
}
執行 answer is 14.142136
/*--------------------------------*/
fabs(計算浮點型數的絕對值)
相關函數:abs
表頭文件:#include<math.h>
定義函數:double fabs(double x);
函數說明:fabs()用來計算浮點型數x的絕對值,然後將結果返回。
返回值:返回參數x的絕對值計算結果
#include <math.h>
main()
{
double answer;
answer=fabs(-3.141592);
printf("|-3.141592|=%f\n",answer);
}
執行結果
|-3.141592|=3.141592
Ⅷ C語言modf()函數問題。
顯示0.2999999是常事喲!就像十進制數不能精準地表達圓周率和自然對數的底e一樣,0.3在計算機中用二進制無法精確表示,找了個離它最接近的小數。
Ⅸ 求C語言的數學函數大全
數學函數(原型聲明所在頭文件為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分解成尾數和階,iptr返回整數部分,函數返回小數部分:fraction = modf(number, &integer);
double fmod(double x,double y) 返回x/y的余數
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() 返回浮點狀態字
Ⅹ C語言庫函數的相關概念
函數名:abort
功 能:異常終止一個進程
函數與形參類型:
void abort(void);
程序例:
#include <stdio.h>
#include <stdlib.h> int main(void)
{
printf(Calling abort()
);
abort();
return 0; /* This is never reached */
} 函數名:abs
功 能:計算整數num的值。返回整數num的絕對值
函數與參數類型:
int abs(num)
int num;
程序例:
#include <stdio.h>
#include <math.h> int main(void)
{
int number = -1234; printf(number: %d absolute value: %d
, number, abs(number));
return 0;
} 函數名: absread, abswirte
功 能:絕對磁碟扇區讀、寫數據
函數與形參類型:
int absread(int drive, int nsects, int sectno, void *buffer);
int abswrite(int drive, int nsects, in tsectno, void *buffer);
程序例:
/* absread example */ #include <stdio.h>
#include <conio.h>
#include <process.h>
#include <dos.h> int main(void)
{
int i, strt, ch_out, sector;
char buf[512]; printf(Insert a diskette into drive A and press any key
);
getch();
sector = 0;
if (absread(0, 1, sector, &buf) != 0)
{
perror(Disk problem);
exit(1);
}
printf(Read OK
);
strt = 3;
for (i=0; i<80; i++)
{
ch_out = buf[strt+i];
putchar(ch_out);
}
printf(
);
return(0);
} 函數名:access
功 能:確定文件的訪問許可權
函數與形參類型:
int access(const char *filename, int amode);
程序例:
#include <stdio.h>
#include <io.h> int file_exists(char *filename); int main(void)
{
printf(Does NOTEXIST.FIL exist: %s
,
file_exists(NOTEXISTS.FIL) ? YES : NO);
return 0;
} int file_exists(char *filename)
{
return (access(filename, 0) == 0);
} 函數名: acos
功 能:計算並返回arccos(x)值、要求-1<=X<=1
函數與形參類型:
double acos(x)
double x;
程序例:
#include <stdio.h>
#include <math.h> int main(void)
{
double result;
double x = 0.5; result = acos(x);
printf(The arc cosine of %lf is %lf
, x, result);
return 0;
} 函數名:allocmem
功 能:分配DOS存儲段
函數與形參類型:
int allocmem(unsigned size, unsigned *seg);
程序例:
#include <dos.h>
#include <alloc.h>
#include <stdio.h> int main(void)
{
unsigned int size, segp;
int stat; size = 64; /* (64 x 16) = 1024 bytes */
stat = allocmem(size, &segp);
if (stat == -1)
printf(Allocated memory at segment: %x
, segp);
else
printf(Failed: maximum number of paragraphs available is %u
,
stat); return 0;
} 函數名:arc
功 能:畫一弧線
函數與形參類型:
void far arc(int x, int y, int stangle, int endangle, int radius);
程序例:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int midx, midy;
int stangle = 45, endangle = 135;
int radius = 100; /* initialize graphics and local variables */
initgraph(&gdriver, &gmode, ); /* read result of initialization */
errorcode = graphresult(); /* an error occurred */
if (errorcode != grOk)
{
printf(Graphics error: %s
, grapherrormsg(errorcode));
printf(Press any key to halt:);
getch(); exit(1); /* terminate with an error code */
} midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(getmaxcolor()); /* draw arc */
arc(midx, midy, stangle, endangle, radius); /* clean up */
getch();
closegraph();
return 0;
} 函數名: asctime
功 能:轉換日期和時間為ASCII碼
函數與形參類型:
char *asctime(const struct tm *tblock);
程序例:
#include <stdio.h>
#include <string.h>
#include <time.h> int main(void)
{
struct tm t;
char str[80]; /* sample loading of tm structure */ t. tm_sec = 1; /* Seconds */
t. tm_min = 30; /* Minutes */
t. tm_hour = 9; /* Hour */
t. tm_mday = 22; /* Day of the Month */
t. tm_mon = 11; /* Month */
t. tm_year = 56; /* Year - does not include century */
t. tm_wday = 4; /* Day of the week */
t. tm_yday = 0; /* Does not show in asctime */
t. tm_isdst = 0; /* Is Daylight SavTime; does not show in asctime */ /* converts structure to null terminated
string */ strcpy(str, asctime(&t));
printf(%s
, str); return 0;
} 函數名::asin
功 能::計算並返回arcsin(x)值、要求-1<=X<=1
函數與形參類型:
double asin(x)
double x;
程序例:
#include <stdio.h>
#include <math.h> int main(void)
{
double result;
double x = 0.5; result = asin(x);
printf(The arc sin of %lf is %lf
, x, result);
return(0);
} 函數名: assert
功 能:測試一個條件並可能使程序終止
函數與形參類型:
void assert(int test);
程序例:
#include <assert.h>
#include <stdio.h>
#include <stdlib.h> struct ITEM {
int key;
int value;
}; /* add item to list, make sure list is not null */
void additem(struct ITEM *itemptr) {
assert(itemptr != NULL);
/* add item to list */
} int main(void)
{
additem(NULL);
return 0;
} 函數名:atan
功 能:計算並返回arctan(x)的值
函數與形參類型:
double atan(double x);
程序例:
#include <stdio.h>
#include <math.h> int main(void)
{
double result;
double x = 0.5; result = atan(x);
printf(The arc tangent of %lf is %lf
, x, result);
return(0);
} 函數名: atan2
功 能:計算並返回arctan(x/y)值
函數與形參類型:
double atan2(double y, double x);
程序例:
#include <stdio.h>
#include <math.h> int main(void)
{
double result;
double x = 90.0, y = 45.0; result = atan2(y, x);
printf(The arc tangent ratio of %lf is %lf
, (y / x), result);
return 0;
} 函數名: atexit
功 能:注冊終止函數
函數與形參類型:
int atexit(atexit_t func);
程序例:
#include <stdio.h>
#include <stdlib.h> void exit_fn1(void)
{
printf(Exit function #1 called
);
} void exit_fn2(void)
{
printf(Exit function #2 called
);
} int main(void)
{
/* post exit function #1 */
atexit(exit_fn1);
/* post exit function #2 */
atexit(exit_fn2);
return 0;
} 函數名: atof
功 能:把str指向的ASCⅡ字元串轉換成一個double型整數返回雙精度的結果
函數與形參類型:
double atof(str)
char*str;
程序例:
#include <stdlib.h>
#include <stdio.h> int main(void)
{
float f;
char *str = 12345.67; f = atof(str);
printf(string = %s float = %f
, str, f);
return 0;
} 函數名:atoi
功 能:
把str指向的ASCⅡz字元串轉換成一個整數。返回整數結果
函數與參數類型:
double atoi(str )
char *str;
程序例:
#include <stdlib.h>
#include <stdio.h> int main(void)
{
int n;
char *str = 12345.67; n = atoi(str);
printf(string = %s integer = %d
, str, n);
return 0;
} 函數名:atol
功 能:
把字元串轉換成長整型數 。返回長整數結果
函數與參數類型:
long atol(str )
char *str;
程序例:
#include <stdlib.h>
#include <stdio.h> int main(void)
{
long l;
char *str = 98765432; l = atol(lstr);
printf(string = %s integer = %ld
, str, l);
return(0);
} 函數名:mkdir
功 能:建立一個目錄
用 法:
int mkdir(char *pathname);
程序例:
#include <stdio.h>
#include <conio.h>
#include <process.h>
#include <dir.h>
int main(void)
{
int status;
clrscr();
status = mkdir(asdfjklm);
(!status) ? (printf(Directory created
)) :
(printf(Unable to create directory
));
getch();
system(dir);
getch();
status = rmdir(asdfjklm);
(!status) ? (printf(Directory deleted
)) :
(perror(Unable to delete directory));
return 0;
} 函數名: mktemp
功 能:建立唯一的文件名
用 法:
char *mktemp(char *template);
程序例:
#include <dir.h>
#include <stdio.h>
int main(void)
{
/* fname defines the template for the
temporary file. */
char *fname = TXXXXXX, *ptr;
ptr = mktemp(fname);
printf(%s
,ptr);
return 0;
} 函數名: MK_FP
功 能:設置一個遠指針
用 法:
void far *MK_FP(unsigned seg, unsigned off);
程序例:
#include <dos.h>
#include <graphics.h>
int main(void)
{
int gd, gm, i;
unsigned int far *screen;
detectgraph(&gd, &gm);
if (gd == HERCMONO)
screen = MK_FP(0xB000, 0);
else
screen = MK_FP(0xB800, 0);
for (i=0; i<26; i++)
screen[i] = 0x0700 + ('a' + i);
return 0;
} 函數名: modf
功 能:把數分為整數和尾數
用 法:
double modf(double value, double *iptr);
程序例:
#include <math.h>
#include <stdio.h>
int main(void)
{
double fraction, integer;
double number = 100000.567;
fraction = modf(number, &integer);
printf(The whole and fractional parts of %lf are %lf and %lf
,
number, integer, fraction);
return 0;
} 函數名: movedata
功 能:拷貝位元組
用 法:
void movedata(int segsrc, int offsrc, int segdest,
int offdest, unsigned numbytes);
程序例:
#include <mem.h>
#define MONO_BASE 0xB000
/* saves the contents of the monochrome screen in buffer */
void save_mono_screen(char near *buffer)
{
movedata(MONO_BASE, 0, _DS, (unsigned)buffer, 80*25*2);
}
int main(void)
{
char buf[80*25*2];
save_mono_screen(buf);
} 函數名: moverel
功 能:將當前位置(CP)移動一相對距離
用 法:
void far moverel(int dx, int dy);
程序例:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
char msg[80];
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, );
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf(Graphics error: %s
, grapherrormsg(errorcode));
printf(Press any key to halt:);
getch();
exit(1); /* terminate with an error code */
}
/* move the C.P. to location (20, 30) */
moveto(20, 30);
/* plot a pixel at the C.P. */
putpixel(getx(), gety(), getmaxcolor());
/* create and output a message at (20, 30) */
sprintf(msg, (%d, %d), getx(), gety());
outtextxy(20, 30, msg);
/* move to a point a relative distance */
/* away from the current value of C.P. */
moverel(100, 100);
/* plot a pixel at the C.P. */
putpixel(getx(), gety(), getmaxcolor());
/* create and output a message at C.P. */
sprintf(msg, (%d, %d), getx(), gety());
outtext(msg);
/* clean up */
getch();
closegraph();
return 0;
} 函數名: movetext
功 能:將屏幕文本從一個矩形區域拷貝到另一個矩形區域
用 法:
int movetext(int left, int top, int right, int bottom,
int newleft, int newtop);
程序例:
#include <conio.h>
#include <string.h>
int main(void)
{
char *str = This is a test string;
clrscr();
cputs(str);
getch();
movetext(1, 1, strlen(str), 2, 10, 10);
getch();
return 0;
} 函數名: moveto
功 能:將CP移到(x, y)
用 法:
void far moveto(int x, int y);
程序例:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
char msg[80];
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, );
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf(Graphics error: %s
, grapherrormsg(errorcode));
printf(Press any key to halt:);
getch();
exit(1); /* terminate with an error code */
}
/* move the C.P. to location (20, 30) */
moveto(20, 30);
/* plot a pixel at the C.P. */
putpixel(getx(), gety(), getmaxcolor());
/* create and output a message at (20, 30) */
sprintf(msg, (%d, %d), getx(), gety());
outtextxy(20, 30, msg);
/* move to (100, 100) */
moveto(100, 100);
/* plot a pixel at the C.P. */
putpixel(getx(), gety(), getmaxcolor());
/* create and output a message at C.P. */
sprintf(msg, (%d, %d), getx(), gety());
outtext(msg);
/* clean up */
getch();
closegraph();
return 0;
} 函數名: movemem
功 能:移動一塊位元組
用 法:
void movemem(void *source, void *destin, unsigned len);
程序例:
#include <mem.h>
#include <alloc.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
char *source = Borland International;
char *destination;
int length;
length = strlen(source);
destination = malloc(length + 1);
movmem(source,destination,length);
printf(%s
,destination);
return 0;
} 函數名: normvideo
功 能:選擇正常亮度字元
用 法:
void normvideo(void);
程序例:
#include <conio.h>
int main(void)
{
normvideo();
cprintf(NORMAL Intensity Text
);
return 0;
} 函數名: nosound
功 能:關閉PC揚聲器
用 法:
void nosound(void);
程序例:
/* Emits a 7-Hz tone for 10 seconds.
True story: 7 Hz is the resonant frequency of a chicken's skull cavity.
This was determined empirically in Australia, where a new factory
generating 7-Hz tones was located too close to a chicken ranch:
When the factory started up, all the chickens died.
Your PC may not be able to emit a 7-Hz tone.
*/
int main(void)
{
sound(7);
delay(10000);
nosound();
}