十年網(wǎng)站開(kāi)發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營(yíng)維護(hù)+專業(yè)推廣+無(wú)憂售后,網(wǎng)站問(wèn)題一站解決
C語(yǔ)言庫(kù)函數(shù),常用庫(kù)函數(shù)有:
創(chuàng)新互聯(lián)于2013年開(kāi)始,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元鹿泉做網(wǎng)站,已為上家服務(wù),為鹿泉各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:13518219792
1、scanf格式輸入函數(shù)
2、printf格式輸出函數(shù)
3、systemdos命令函數(shù)
4、sort排序
5、main主函數(shù)
6、fgets文件讀取字符串函數(shù)
7、fputs文件寫入字符串函數(shù)
8、fscanf文件格式讀取函數(shù)
9、fprintf文件格式寫入函數(shù)
10、fopen打開(kāi)文件函數(shù)
11、getchar輸入字符函數(shù)
12、putchar輸出字符函數(shù)
13、malloc動(dòng)態(tài)申請(qǐng)內(nèi)存函數(shù)
14、free釋放內(nèi)存函數(shù)
15、abs求絕對(duì)值數(shù)學(xué)函數(shù)
16、sqrt求平方根數(shù)學(xué)函數(shù)
擴(kuò)展資料
語(yǔ)言組成:
1、數(shù)據(jù)類型
C的數(shù)據(jù)類型包括:整型、字符型、實(shí)型或浮點(diǎn)型(單精度和雙精度)、枚舉類型、數(shù)組類型、結(jié)構(gòu)體類型、共用體類型、指針類型和空類型。
2、常量與變量
常量其值不可改變,符號(hào)常量名通常用大寫。
變量是以某標(biāo)識(shí)符為名字,其值可以改變的量。標(biāo)識(shí)符是以字母或下劃線開(kāi)頭的一串由字母、數(shù)字或下劃線構(gòu)成的序列,請(qǐng)注意第一個(gè)字符必須為字母或下劃線,否則為不合法的變量名。變量在編譯時(shí)為其分配相應(yīng)存儲(chǔ)單元。
3、數(shù)組
如果一個(gè)變量名后面跟著一個(gè)有數(shù)字的中括號(hào),這個(gè)聲明就是數(shù)組聲明。字符串也是一種數(shù)組。它們以ASCII的NULL作為數(shù)組的結(jié)束。要特別注意的是,方括內(nèi)的索引值是從0算起的。
4、指針
如果一個(gè)變量聲明時(shí)在前面使用 * 號(hào),表明這是個(gè)指針型變量。換句話說(shuō),該變量存儲(chǔ)一個(gè)地址,而 *(此處特指單目運(yùn)算符 * ,下同。C語(yǔ)言中另有 雙目運(yùn)算符 *) 則是取內(nèi)容操作符,意思是取這個(gè)內(nèi)存地址里存儲(chǔ)的內(nèi)容。指針是 C 語(yǔ)言區(qū)別于其他同時(shí)代高級(jí)語(yǔ)言的主要特征之一。
參考資料來(lái)源:百度百科-函數(shù)
函數(shù)名: abort
功 能: 異常終止一個(gè)進(jìn)程
用 法: void abort(void);
程序例:
#include stdio.h
#include stdlib.h
int main(void)
{
printf("Calling abort()\n");
abort();
return 0; /* This is never reached */
}
函數(shù)名: abs
功 能: 求整數(shù)的絕對(duì)值
用 法: int abs(int i);
程序例:
#include stdio.h
#include math.h
int main(void)
{
int number = -1234;
printf("number: %d absolute value: %d\n", number, abs(number));
return 0;
}
函數(shù)名: absread, abswirte
功 能: 絕對(duì)磁盤扇區(qū)讀、寫數(shù)據(jù)
用 法: 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\n");
getch();
sector = 0;
if (absread(0, 1, sector, buf) != 0)
{
perror("Disk problem");
exit(1);
}
printf("Read OK\n");
strt = 3;
for (i=0; i80; i++)
{
ch_out = buf[strt+i];
putchar(ch_out);
}
printf("\n");
return(0);
}
函數(shù)名: access
功 能: 確定文件的訪問(wèn)權(quán)限
用 法: 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\n",
file_exists("NOTEXISTS.FIL") ? "YES" : "NO");
return 0;
}
int file_exists(char *filename)
{
return (access(filename, 0) == 0);
}
函數(shù)名: acos
功 能: 反余弦函數(shù)
用 法: double acos(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\n", x, result);
return 0;
}
函數(shù)名: allocmem
功 能: 分配DOS存儲(chǔ)段
用 法: 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\n", segp);
else
printf("Failed: maximum number of paragraphs available is %u\n",
stat);
return 0;
}
函數(shù)名: 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\n", 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;
}
函數(shù)名: asctime
功 能: 轉(zhuǎn)換日期和時(shí)間為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\n", str);
return 0;
}
函數(shù)名: asin
功 能: 反正弦函數(shù)
用 法: double asin(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\n", x, result);
return(0);
}
函數(shù)名: assert
功 能: 測(cè)試一個(gè)條件并可能使程序終止
用 法: 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;
}
函數(shù)名: atan
功 能: 反正切函數(shù)
用 法: 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\n", x, result);
return(0);
}
函數(shù)名: atan2
功 能: 計(jì)算Y/X的反正切值
用 法: 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\n", (y / x), result);
return 0;
}
函數(shù)名: atexit
功 能: 注冊(cè)終止函數(shù)
用 法: int atexit(atexit_t func);
程序例:
#include stdio.h
#include stdlib.h
void exit_fn1(void)
{
printf("Exit function #1 called\n");
}
void exit_fn2(void)
{
printf("Exit function #2 called\n");
}
int main(void)
{
/* post exit function #1 */
atexit(exit_fn1);
/* post exit function #2 */
atexit(exit_fn2);
return 0;
}
函數(shù)名: atof
功 能: 把字符串轉(zhuǎn)換成浮點(diǎn)數(shù)
用 法: double atof(const char *nptr);
程序例:
#include stdlib.h
#include stdio.h
int main(void)
{
float f;
char *str = "12345.67";
f = atof(str);
printf("string = %s float = %f\n", str, f);
return 0;
}
函數(shù)名: atoi
功 能: 把字符串轉(zhuǎn)換成長(zhǎng)整型數(shù)
用 法: int atoi(const char *nptr);
程序例:
#include stdlib.h
#include stdio.h
int main(void)
{
int n;
char *str = "12345.67";
n = atoi(str);
printf("string = %s integer = %d\n", str, n);
return 0;
}
函數(shù)名: atol
功 能: 把字符串轉(zhuǎn)換成長(zhǎng)整型數(shù)
用 法: long atol(const char *nptr);
程序例:
#include stdlib.h
#include stdio.h
int main(void)
{
long l;
char *str = "98765432";
l = atol(lstr);
printf("string = %s integer = %ld\n", str, l);
return(0);
}
/*輸出9*9口訣。共9行9列,i控制行,j控制列。*/
#include "stdio.h"
main()
{int i,j,result;
for (i=1;i10;i++)
{ for(j=1;j10;j++)
{
result=i*j;
printf("%d*%d=%-3d",i,j,result);/*-3d表示左對(duì)齊,占3位*/
}
printf("\n");/*每一行后換行*/
}
}
擴(kuò)展資料:
C語(yǔ)言的字符串其實(shí)就是以'\0'字符結(jié)尾的char型數(shù)組,使用字符型并不需要引用庫(kù),但是使用字符串就需要C標(biāo)準(zhǔn)庫(kù)里面的一些用于對(duì)字符串進(jìn)行操作的函數(shù)。它們不同于字符數(shù)組。使用這些函數(shù)需要引用頭文件string.h。
文件輸入/輸出
在C語(yǔ)言中,輸入和輸出是經(jīng)由標(biāo)準(zhǔn)庫(kù)中的一組函數(shù)來(lái)實(shí)現(xiàn)的。在ANSI C中,這些函數(shù)被定義在頭文件stdio.h;中。
標(biāo)準(zhǔn)輸入/輸出
有三個(gè)標(biāo)準(zhǔn)輸入/輸出是標(biāo)準(zhǔn)I/O庫(kù)預(yù)先定義的:
stdin標(biāo)準(zhǔn)輸入
stdout標(biāo)準(zhǔn)輸出
stderr輸入輸出錯(cuò)誤
參考資料來(lái)源:百度百科-c語(yǔ)言
C語(yǔ)言的常用庫(kù)函數(shù)
函數(shù)1。absread()讀磁盤絕對(duì)扇區(qū)函數(shù)
函數(shù)2。abswrite()寫磁盤絕對(duì)扇區(qū)函數(shù)
函數(shù)3。atof()將字符串轉(zhuǎn)換成浮點(diǎn)數(shù)的函數(shù)
函數(shù)4。atoi()將字符串轉(zhuǎn)換成整型數(shù)的函數(shù)
函數(shù)5。atol()將字符串轉(zhuǎn)換成長(zhǎng)整型數(shù)的函數(shù)
函數(shù)6。bcd()把一個(gè)數(shù)轉(zhuǎn)換成對(duì)應(yīng)的BCD碼的函數(shù)
函數(shù)7。bdos()
函數(shù)8。biosdisk()調(diào)用BIOS磁盤驅(qū)動(dòng)程序函數(shù)
函數(shù)9。biosprint()調(diào)用BIOS打印機(jī)I/O接口的函數(shù)
函數(shù)10。calloc()分配內(nèi)存函數(shù)
函數(shù)11。ceil()
函數(shù)12。cgets()讀字符串函數(shù)
函數(shù)13。chdir()改變當(dāng)前目錄的函數(shù)
函數(shù)14。_chmod()改變文件存取權(quán)限的函數(shù)
函數(shù)15。chmod()改變文件存取權(quán)限的函數(shù)
函數(shù)16。clock()
函數(shù)17。close()關(guān)閉文件函數(shù)
函數(shù)18。closegraph()關(guān)閉圖形函數(shù)
函數(shù)19。cos()
函數(shù)20。ctrlbrk()設(shè)置ctrl-break處理程序的函數(shù)
函數(shù)21。delay()暫停函數(shù)
函數(shù)22。disable()屏蔽中斷的宏
函數(shù)23。enable()開(kāi)硬件中斷的宏
函數(shù)24。exec()加載并運(yùn)行其它程序的函數(shù)族
函數(shù)25。farcalloc()從遠(yuǎn)堆中分配內(nèi)存的函數(shù)
函數(shù)26。farfree()從遠(yuǎn)堆中釋放一塊已分配內(nèi)存的函數(shù)
函數(shù)27。farmalloc()從遠(yuǎn)堆中分配內(nèi)存的函數(shù)
函數(shù)28。farrealloc()調(diào)整遠(yuǎn)堆中已分配塊的函數(shù)
函數(shù)29。fclose()關(guān)閉一個(gè)流函數(shù)
函數(shù)30。fcloseall()關(guān)閉打開(kāi)的流的函數(shù)
函數(shù)31。feof()檢查文件是否結(jié)束的函數(shù)
函數(shù)32。fgets()從流中讀取一字符串的函數(shù)
函數(shù)33。findfirst()函數(shù)和findnext()函數(shù)
函數(shù)34。floodfill()填充區(qū)域的函數(shù)
函數(shù)35。floor()
函數(shù)36。fnmerge()建立文件路徑函數(shù)
函數(shù)37。fnsplit()分解完整的路徑名函數(shù)
函數(shù)38。fopen()打開(kāi)一個(gè)流函數(shù)
函數(shù)39。FP_OFF()獲取遠(yuǎn)地址偏移量的宏
函數(shù)40。fprintf()傳送輸出到一個(gè)流中的函數(shù)
函數(shù)41。FP_SEG()獲取遠(yuǎn)地址段值的宏
函數(shù)42。fscanf()格式化輸入函數(shù)
函數(shù)43。fseek()移動(dòng)文件指針函數(shù)
函數(shù)44。fwrite()把參數(shù)寫入流中的函數(shù)
函數(shù)45。gcvt()把雙精度數(shù)轉(zhuǎn)化成字符串的函數(shù)
函數(shù)46。geninterrupt()執(zhí)行中斷函數(shù)
函數(shù)47。getc()從流中取字符的宏
函數(shù)48。getch()從鍵盤無(wú)回顯地讀取一字符的函數(shù)
函數(shù)49。getchar()從stdin流中讀取一個(gè)字符的函數(shù)
函數(shù)50。getcurdir()讀取指定驅(qū)動(dòng)器的當(dāng)前目錄的函數(shù)
函數(shù)61。getcwd()讀取當(dāng)前目錄的函數(shù)
函數(shù)62。getdate()讀取系統(tǒng)日期函數(shù)
函數(shù)63。getdfree()讀取磁盤空閑空間的函數(shù)
函數(shù)64。getdisk()讀取當(dāng)前磁盤驅(qū)動(dòng)器號(hào)函數(shù)
函數(shù)65。getenv()讀取環(huán)境變量的當(dāng)前值的函數(shù)
函數(shù)66。getimage()將指定區(qū)域的位圖象存入內(nèi)存的函數(shù)
函數(shù)67。getmaxx()返回屏幕上最大的X坐標(biāo)值的函數(shù)
函數(shù)68。getmaxy()返回屏幕上最大的Y坐標(biāo)值的函數(shù)
函數(shù)69。getpixel()讀取像素顏色的函數(shù)
函數(shù)70。getpsp()
函數(shù)71。gets()從標(biāo)準(zhǔn)輸入流stdio中讀取一字符串的函數(shù)
函數(shù)72。gettime()讀取系統(tǒng)時(shí)間的函數(shù)
函數(shù)73。getvect()讀取中斷向量函數(shù)
函數(shù)74。getx()返回當(dāng)前圖形方式下位置的X坐標(biāo)值的函數(shù)
函數(shù)75。gety()返回當(dāng)前圖形方式下位置的Y坐標(biāo)值的函數(shù)
函數(shù)76。imagesize()返回保存圖像緩沖區(qū)大小的函數(shù)
函數(shù)77。initgraph()顯示模式控制函數(shù)(初始化圖形系統(tǒng)函數(shù))
函數(shù)78。inport()從端口中讀入一個(gè)字的函數(shù)
函數(shù)79。inportb()從端口讀入一個(gè)字節(jié)的函數(shù)
函數(shù)80。int86()執(zhí)行中斷函數(shù)(調(diào)用8086軟中斷函數(shù))
函數(shù)81。int86x()執(zhí)行中斷函數(shù) (通用8086軟中斷接口函數(shù))
函數(shù)82。intdos()通用dos中斷接口函數(shù)
函數(shù)83。intdosx()通用dos中斷接口函數(shù)
函數(shù)84。intr()執(zhí)行8086軟中斷函數(shù)(改變軟中斷接口函數(shù))
函數(shù)85。itoa()把整形數(shù)轉(zhuǎn)換為字符串的函數(shù)
函數(shù)86。kbhit()檢查當(dāng)前按下的鍵的函數(shù)
函數(shù)87。keep()駐留并退出函數(shù)
函數(shù)88。log()
函數(shù)89。log10()
函數(shù)90。_lrotl()將一個(gè)無(wú)符號(hào)長(zhǎng)整形數(shù)左循環(huán)移位的函數(shù)
函數(shù)91。_lrotr()將一個(gè)無(wú)符號(hào)長(zhǎng)整形數(shù)右循環(huán)移位的函數(shù)
函數(shù)92。lseek()移動(dòng)文件指針函數(shù)
函數(shù)93。ltoa()把長(zhǎng)整形數(shù)轉(zhuǎn)換為字符串的函數(shù)
函數(shù)94。malloc()分配內(nèi)存函數(shù)
函數(shù)95。mkdir()創(chuàng)建目錄函數(shù)
函數(shù)96。mktemp()建立一個(gè)唯一的文件名的函數(shù)
函數(shù)97。MK_FP()設(shè)置一個(gè)遠(yuǎn)指針的宏
函數(shù)98。movedata()拷貝數(shù)據(jù)函數(shù)
函數(shù)99。_open()打開(kāi)一個(gè)文件進(jìn)行讀寫的函數(shù)
函數(shù)100。open()打開(kāi)文件進(jìn)行讀寫的函數(shù)
函數(shù)101。outport()輸出一個(gè)字到端口中的函數(shù)
函數(shù)102。outportb()輸出一個(gè)字節(jié)到端口中的函數(shù)
函數(shù)103。outtextxy()在指定位置顯示一字符串的函數(shù)
函數(shù)104。peek()返回指定內(nèi)存中字的函數(shù)
函數(shù)105。peekb()返回指定內(nèi)存中字節(jié)的函數(shù)
函數(shù)106。poke()在指定的內(nèi)存中存儲(chǔ)一個(gè)字的函數(shù)
函數(shù)107。pokeb()在指定的內(nèi)存中存儲(chǔ)一個(gè)字節(jié)的函數(shù)
函數(shù)108。pow()
函數(shù)109。printf()寫格式化輸出到stdout的函數(shù)
函數(shù)110。putch()向屏幕輸出字符的函數(shù)
函數(shù)111。putchar()在stdout上輸出字符的宏
函數(shù)112。putenv()將字符串放入當(dāng)前環(huán)境中的函數(shù)
函數(shù)113。putimage()重新寫屏函數(shù)(輸出一個(gè)位圖象到圖形屏幕上的函數(shù))
函數(shù)114。putpixel()寫像素點(diǎn)函數(shù)
函數(shù)115。puts()輸出一字符串到stdout(標(biāo)準(zhǔn)輸出)的函數(shù)
函數(shù)116。_read()讀文件函數(shù)
函數(shù)117。read()讀文件函數(shù)
函數(shù)118。realloc()重新分配內(nèi)存函數(shù)
函數(shù)119。rectangle()畫一個(gè)矩形的函數(shù)
函數(shù)120。remove()刪除一個(gè)文件的函數(shù)
函數(shù)121。rename()文件改名函數(shù)
函數(shù)122。restorecrtmode()恢復(fù)屏幕視頻模式為調(diào)用initgraph前的設(shè)置的函數(shù)
函數(shù)123。rmdir()刪除目錄函數(shù)
函數(shù)124。_rotl()將一個(gè)無(wú)符號(hào)整形數(shù)左循環(huán)移位的函數(shù)
函數(shù)125。_rotr()將一個(gè)無(wú)符號(hào)整形數(shù)右循環(huán)移位的函數(shù)
函數(shù)126。scanf()格式化輸入函數(shù)
函數(shù)127。searchpath()按dos路徑查找一個(gè)文件的函數(shù)
函數(shù)128。segread()讀段寄存器函數(shù)
函數(shù)129。setactivepage()設(shè)置圖形輸出活動(dòng)頁(yè)的函數(shù)
函數(shù)130。setcolor()設(shè)置當(dāng)前要畫的線顏色的函數(shù)
函數(shù)131。setdisk()設(shè)置當(dāng)前驅(qū)動(dòng)器的函數(shù)
函數(shù)132。setgraphmode()將系統(tǒng)設(shè)置成圖形模式并清屏的函數(shù)
函數(shù)133。setlinestyle()設(shè)置當(dāng)前畫線寬度和類型的函數(shù)
函數(shù)134。settextstyle()顯示字符的當(dāng)前設(shè)置函數(shù)
函數(shù)135。setvect()設(shè)置中斷向量函數(shù)
函數(shù)136。setviewport()建立視口的函數(shù)
函數(shù)137。setvisualpage()設(shè)置可見(jiàn)的圖形頁(yè)號(hào)的函數(shù)
函數(shù)138。sin()
函數(shù)139。sprintf()格式化輸出到數(shù)組的函數(shù)
函數(shù)140。strcat()
函數(shù)141。tan()
函數(shù)142。_write()寫文件函數(shù)
函數(shù)143。write()寫文件函數(shù)
原文釋義請(qǐng)到百度文庫(kù)里搜尋字串“C語(yǔ)言常用函數(shù)”后下載
函數(shù)51-60因原注里排序號(hào)碼少編,所以只有133個(gè)常用函數(shù)。
DOC大小是119.5KB
貢獻(xiàn)時(shí)間:2010-09-10
貢獻(xiàn)者:handanlinzhang