C語言標準庫(瞭解)

[+]

概述

      C語言函數手冊也稱爲C標準庫。C標準庫由在15個頭文件中聲明的函數、類型定義和宏組成,每個頭文件都代表了一定範圍的編程功能。有人說,C標準庫可以分爲 3 組,如何正確並熟練的使用它們,可以相應的可區分出 3 個層次的程序員:

合格程序員:<stdio.h><ctype.h><stdlib.h><string.h>

熟練程序員:<assert.h><limits.h><stddef.h><time.h>

優秀程序員:<float.h><math.h><error.h><locale.h><setjmp.h><signal.h><stdarg.h>

一,<math.h>裏的數學計算公式介紹   

    1、三角函數 
    double sin (double);正弦 
    double cos (double);餘弦 
    double tan (double);正切 
   2 、反三角函數 
    double asin (double); 結果介於[-PI/2, PI/2] 
    double acos (double); 結果介於[0, PI] 
    double atan (double); 反正切(主值), 結果介於[-PI/2, PI/2] 
    double atan2 (double, double); 反正切(整圓值), 結果介於[-PI, PI] (y/x的反正切值)
   3 、雙曲三角函數 
    double sinh (double); 
    double cosh (double); 
    double tanh (double); 
   4 、指數與對數 
    double exp (double);求取自然數e的冪 (以e爲底的x次方值)
    double sqrt (double);開平方 
    double log (double); 以e爲底的對數 
    double log10 (double);以10爲底的對數 
    double pow(double x, double y);計算以x爲底數的y次冪 
    float powf(float x, float y); 功能與pow一致,只是輸入與輸出皆爲浮點數 
         double pow10(double x, double y);求10的x次方(次冪)
  5 、取整 
   double ceil (double); 取上整 (即求不小於某個數的最小整數)
   double floor (double); 取下整 (即求不大於某個數的最大整數)
  6、絕對值 
    double fabs (double);求絕對值 
    double cabs(struct complex znum) ;求複數的絕對值 
         int        abs(int);      求整數的絕對值
         long      labs(long);  取長整型絕對值7 、標準化浮點數 
   double frexp (double f, int *p); 標準化浮點數, f = x * 2^p, 已知f求x, p ( x介於[0.5, 1] ) 
   double ldexp (double x, int p); 與frexp相反, 已知x, p求f 
 7 、取整與取餘 
  double modf (double, double*); 將參數的整數部分通過指針回傳, 返回小數部分 
  double fmod (double, double); 返回兩參數相除的餘數 (對浮點數取模)
 8 、其他 
  double hypot(double x, double y);已知直角三角形兩個直角邊長度,求斜邊長度 
  double ldexp(double x, int exponent);計算x*(2的exponent次冪) 
  double poly(double x, int degree, double coeffs [] );計算多項式 
       double round( double); 四捨五入取整
       double fmax(double, double);求最大值
       double min(double,double);求最小值
       int        rand(void); 求隨機數

注意事項:
沒有現成的cot三角函數,可以使用tan(PI/2-x)來實現
強調一點,1-3類 傳參都是針對以弧度表示的數值,非角度表示的數值。
對於一般的對數求解,考慮利用數學上的對數轉換來實現。
關於fmod:考慮到%只適用與整型數據,這裏提出一個專門針對實型數據的取餘運算的函數。
int rand(void) 用這函數的時候記得要給隨機種子哦,要不得出的不是真正的隨機數.產生隨機種子可以用srand((unsigned int)time(NULL));這就是由時間產生的隨機種子了。

二,<assert.h>函數

    assert.h C標準庫的頭文件中提供了一個宏稱爲斷言可以用於驗證程序的假設,如果這個假設是錯誤的,並打印診斷消息。

    以下是唯一的函數定義在頭assert.h:  

    void assert(int expression)

    這實際上是一個宏,而不是一個函數,它可以被用來添加在C程序診斷。expression 相當於 if裏面的表達式

示例:

[objc] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. - (void)viewDidLoad {  
  2.    [super viewDidLoad];  
  3.    int i =1;  
  4.    assert(i>1);  
  5.    NSLog(@"打印出i的值是:%d",i);  

打印結果:

[objc] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. Assertion failed: (i>1), function -[ViewController viewDidLoad], file /Users/admin/Desktop/xcodeCode/math.h/math.h/ViewController.m, line 20.  

注意:

       * assert是一個宏,只在debug版本中起作用,在release版本中,該語句是不起任何作用的。()   

       * 當assert診斷失敗後,assert會向stderr打印消息。從圖1可以看出,assert診斷信息的表達形式是:Assertion failed: 表達式(expression),程序(file) 出錯的文件名(file name), 行號(line nnn)。然後,asset會調用abort中斷函數的執行,源代碼的文件名(The Source filename)和行號(line number)定義在預處理宏(preprocessor macros)__FILE__ 和 __LINE__中

      *在調試結束後,可以通過在包含#include <assert.h>的語句之前插入 #define NDEBUG 來禁用assert調用,

示例代碼如下:

[objc] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. <span style="font-size:12px;">      #include <stdio.h>  
  2.       #define NDEBUG  
  3.       #include <assert.h></span>  

      *NSAssert 在 Objective - c 裏面也是宏,他的做用跟 assert()幾乎一樣 ,release 模式下就 什麼也不執行 ,debug 就會 斷言 。(release模式下 xcode定義了一個宏 NS_BLOCK_ASSERTIONS ,這個 宏 跟 c 裏面的 NDEBUG 異曲同工)
      NSAssert(condition,desc) , 在 debug模式下 被翻譯成

[objc] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. <span style="font-size:12px;">      if (!(condition)) {   
  2.          [[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd   
  3.                                                                                      object:self file:[NSString stringWithUTF8String:__FILE__]   
  4.                                                                             lineNumber:__LINE__ description:(desc), ##__VA_ARGS__];   
  5.        }</span>  

        參數:condition是條件表達式,值爲YES或NO;

                desc爲異常描述,通常爲NSString。

        當conditon爲YES時程序繼續運行,爲NO時,則拋出帶有desc描述的異常信息

三,<ctype.h>函數

ctype.h是C標準函數庫中的頭文件,定義了一批C語言字符分類函數(C character classification functions),用於測試字符是否屬於特定的字符類別,如字母字符、控制字符等等。既支持單字節(Byte)字符,也支持寬字符。

*庫函數
以下是在頭文件ctype.h中定義的函數:
S.N.函數及說明
1      int isalnum(int c)
        該函數檢查傳遞的字符是否是字母數字。
2int isalpha(int c)
        該函數是否傳遞的字符是字母。
3int iscntrl(int c)
        該函數是否傳遞的字符是控制字符。
4int isdigit(int c)
        該函數是否傳遞的字符是十進制數字。
5int isgraph(int c)
        該函數是否傳遞的字符的圖形表示,使用的語言環境。
6int islower(int c)
        該函數檢查傳遞的字符是否是小寫字母。
7int isprint(int c)
        該函數檢查傳遞的字符是否是可打印的。
8int ispunct(int c)
        該函數檢查傳遞的字符是否是標點符號。
9int isspace(int c)
        該函數檢查傳遞的字符是否是空白。
10int isupper(int c)
        該函數檢查傳遞的字符是否是大寫字母。
11int isxdigit(int c)
       該函數檢查傳遞的字符是否是十六進制數字。該庫還包含兩個轉換函數,也接受並返回一個“整數”
S.N.函數及說明
1int tolower(int c)
       這個函數轉換大寫字母爲小寫。
2int toupper(int c)
       這個函數小寫字母轉換爲大寫。 字符類

示例和詳情請查看百度百科

四,<errno.h>函數

errno.h中的C標準庫的頭文件中定義的整數變量errno,這是由系統調用和一些庫函數的錯誤事件指明什麼地方出了錯。該宏展開爲int類型的修改的左值,因此它可以同時讀取和修改程序。
errno設置爲零,在程序啓動時,標準C庫中的某些功能修改它的值到一些異於零值,某些類型的錯誤信號。您還可以修改它的值,或在方便時歸零。
errno.h中頭文件還定義了一個宏表示不同的錯誤代碼,而應擴大到int類型的整數常量表達式列表。
*庫宏
以下是在頭errno.h中定義的宏: 
S.N.宏及說明
1extern int  errno
        這是宏集合系統調用和一些庫函數的錯誤事件指明什麼地方出了錯。
2EDOM Domain Error
        這個宏域發生的錯誤,如果輸入參數是外域的數學函數的定義,並設置errno爲EDOM。
3ERANGE Range Error
        這個宏代表的一系列發生的錯誤,如果輸入參數的範圍之外的數學函數的定義,並且errno被設置爲ERANGE。

五,float.h函數

float.h中的C標準庫的頭文件包含了一組浮點值相關的各種平臺相關的常數。這些常量是由ANSI C允許更多的可移植程序提出。之前檢查所有的常量,它是很好的理解浮點數是由以下四個元素:
組件 組件說明
S sign ( +/- )
b base or radix of the exponent representation, 2 for binary, 10 for decimal, 16 for hexadecimal, and so on...
e exponent, an integer between a minimum emin and a maximum emax.
p precision, the number of base-b digits in the significand
上述4個組成部分的基礎上,一個浮點將它的值,如下所示:

[objc] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. f被定義的宏編輯  
  2. double  
  3. DBL_DIG double  
  4. //小數點後面精確的位數  
  5. DBL_EPSILON  
  6. //小的正數 ,double的0跨度值  
  7. DBL_MANT_DIG  
  8. //尾數中的位數  
  9. DBL_MAX  
  10. //最大值  
  11. DBL_MAX_10_EXP  
  12. //最大10進制指數  
  13. DBL_MAX_EXP  
  14. //最大2進制指數  
  15. DBL_MIN  
  16. //最小值  
  17. DBL_MIN_10_EXP  
  18. //最小10進制指數  
  19. DBL_MIN_EXP  
  20. //最小2進制指數  
  21. float  
  22. FLT_DIG  
  23. float//小數點後面精確的位數  
  24. FLT_EPSILON  
  25. //小的正數,float的0跨度值  
  26. FLT_MANT_DIG  
  27. //尾數中的位數  
  28. FLT_MAX  
  29. //最大值  
  30. FLT_MAX_10_EXP  
  31. //最大10進制指數  
  32. FLT_MAX_EXP  
  33. //最大2進制指數  
  34. FLT_MIN  
  35. //最小值  
  36. FLT_MIN_10_EXP  
  37. //最小10進制指數  
  38. FLT_MIN_EXP  
  39. //最小2進制指數  
  40. FLT_RADIX  
  41. //進制基數  
  42. FLT_ROUNDS  
  43. //加法舍入  
  44. long double  
  45. LDBL_DIG  
  46. long double//小數點後面精確的位數  
  47. LDBL_EPSILON  
  48. //小的正數,long double的0跨度值  
  49. LDBL_MANT_DIG  
  50. //尾數中的位數  
  51. LDBL_MAX  
  52. //最大值  
  53. LDBL_MAX_10_EXP  
  54. //最大10進制指數  
  55. LDBL_MAX_EXP  
  56. //最大2進制指數  
  57. LDBL_MIN  
  58. //最小值  
  59. LDBL_MIN_10_EXP  
  60. //最小10進制指數  
  61. LDBL_MIN_EXP  
  62. //最小2進制指數 [1]   
These macros define the minimum floating-yiibai value.. 例子
下面的例子演示瞭如何使用幾個在float.h文件中定義的常量。

[objc] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. <span style="font-size:12px;">#include <stdio.h>  
  2. #include <float.h>  
  3. int main(){  
  4.    printf("The maximum value of float = %.10e  
  5. ", FLT_MAX);  
  6.    printf("The minimum value of float = %.10e  
  7. ", FLT_MIN);  
  8.   
  9.    printf("The number of digits in the number = %.10e  
  10. ", FLT_MANT_DIG);  
  11. }</span>  
讓我們編譯和運行上面的程序,這將產生以下結果:
[objc] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. The maximum value of float = 3.4028234664e+38  
  2. The minimum value of float = 1.1754943508e-38  
  3. The number of digits in the number = 7.2996655210e-312  

六,limits.h函數

limits.h頭中確定各種變量類型的各種屬性。在這個頭中定義的宏限制的char,int和long類型,如各種變量的值。
這些限制指定一個變量,無法存儲任何值超越這些限制,例如一個無符號的字符最多可以存儲的最大值爲255。
*庫宏
下面的值是特定於實現定義#define指令,但這些數值可能沒有任何比這裏給出更低(小)。
                    值         描述
CHAR_BIT    8                定義了一個字節中的比特數。
SCHAR_MIN -127        定義最小值簽署的字符。
SCHAR_MAX  127        定義最大值簽署的字符。
UCHAR_MAX  255        定義unsigned char類型的最大值。
CHAR_MIN   0                char類型定義最小值,它的值將等於SCHAR_MIN如果char表示負值,否則爲零。
CHAR_MAX 127                定義char類型的值,它的值將等於SCHAR_MAX的char代表負值,否則UCHAR_MAX,
MB_LEN_MAX  1                定義的最大字節數多字節字符。
SHRT_MIN-32767        定義一個短整型的最小值。
SHRT_MAX+32767        定義一個短整型的最大值。
USHRT_MAX65535        定義一個無符號的短整型的最大值。
INT_MIN       -32767        定義類型爲int的最小值。
INT_MAX+32767        定義一個int的最大值。
UINT_MAX65535        定義一個unsigned int的最大值。
LONG_MIN-2147483647定義一個長整型的最小值。
LONG_MAX+2147483647定義一個長整型的最大值。
ULONG_MAX4294967295定義一個無符號長整型的最大值。 例子
下面的例子顯示的幾個常量定義在limit.h文件的用法。

[objc] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. #include <stdio.h>  
  2. #include <limits.h>  
  3. int main(){  
  4.    printf("The number of bits in a byte %d  
  5. ", CHAR_BIT);  
  6.    printf("The minimum value of SIGNED CHAR = %d  
  7. ", SCHAR_MIN);  
  8.    printf("The maximum value of SIGNED CHAR = %d  
  9. ", SCHAR_MAX);  
  10.    printf("The maximum value of UNSIGNED CHAR = %d  
  11. ", UCHAR_MAX);  
  12.    printf("The minimum value of SHORT INT = %d  
  13. ", SHRT_MIN);  
  14.    printf("The maximum value of SHORT INT = %d  
  15. ", SHRT_MAX);   
  16.    printf("The minimum value of INT = %d  
  17. ", INT_MIN);  
  18.    printf("The maximum value of INT = %d  
  19. ", INT_MAX);  
  20.    printf("The minimum value of CHAR = %d  
  21. ", CHAR_MIN);  
  22.    printf("The maximum value of CHAR = %d  
  23. ", CHAR_MAX);  
  24.    printf("The minimum value of LONG = %ld  
  25. ", LONG_MIN);  
  26.    printf("The maximum value of LONG = %ld  
  27. ", LONG_MAX);   
  28.    return(0);  
  29. }  
讓我們編譯和運行上面的程序,這將產生以下結果:
[objc] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. The number of bits in a byte 8  
  2. The minimum value of SIGNED CHAR = -128  
  3. The maximum value of SIGNED CHAR = 127  
  4. The maximum value of UNSIGNED CHAR = 255  
  5. The minimum value of SHORT INT = -32768  
  6. The maximum value of SHORT INT = 32767  
  7. The minimum value of INT = -32768  
  8. The maximum value of INT = 32767  
  9. The minimum value of CHAR = -128  
  10. The maximum value of CHAR = 127  
  11. The minimum value of LONG = -2147483648  
  12. The maximum value of LONG = 2147483647  

七,locale.h函數

locale.h頭文件定義了特定的位置設置,如日期格式和貨幣符號。有一個重要的結構struct lconv和兩個重要的函數,下面列出一些宏定義。
*庫宏
以下是在標頭中定義的宏,這些宏將被用在下面列出的兩個函數:

S.N.  宏及說明
1 LC_ALL
   Set everything.
2 LC_COLLATE
   Affects strcoll and strxfrm functions.
3 LC_CTYPE
   Affects all character functions.
4 LC_MONETARY
   Affects the monetary information provided by localeconv function.
5 LC_NUMERIC
   Affects decimal-yiibai formatting and the information provided by localeconv function.
6 LC_TIME
   Affects the strftime function. 庫函數

以下是頭locale.h中定義的函數:

S.N.  功能及說明
1 char *setlocale(int category, const char *locale)
       設置或讀取位置相關的信息。
2 struct lconv *localeconv(void)
       設置或讀取位置相關的信息。 庫結構 
typedef struct {
   char *decimal_yiibai;
   char *thousands_sep;
   char *grouping;
   char *int_curr_symbol;
   char *currency_symbol;
   char *mon_decimal_yiibai;
   char *mon_thousands_sep;
   char *mon_grouping;
   char *positive_sign;
   char *negative_sign;
   char int_frac_digits;
   char frac_digits;
   char p_cs_precedes;
   char p_sep_by_space;
   char n_cs_precedes;
   char n_sep_by_space;
   char p_sign_posn;
   char n_sign_posn;
} iconv

八,setjmp.h函數

setjmp.h 頭定義宏的setjmp(),一個函數longjmp()和一個可變typejmp_buf的繞過正常的函數調用和返回學科。
*庫變量
以下是在頭setjmp.h中定義的變量類型:
S.N.變量和說明
1jmp_buf 
這是一個數組類型用於宏調用setjmp()和longjmp的()函數持有信息。 庫宏
只有一個在這個庫中定義的宏:

S.N.宏觀與說明
1int setjmp(jmp_buf environment)
        此宏保存當前的環境下入變量的環境中由函數longjmp()以供以後使用。如果該宏返回直接從宏調用,它返回零,但如果它返回的longjmp()函數調用,則返回一個非零值。 庫函數
以下是定義在頭setjmp.h中只有一個函數:

S.N.函數及說明
1void longjmp(jmp_buf environment, int value)
       此函數恢復由最近一次調用setjmp()調用到jmp_buf參數與相應的程序在同一調用宏保存的環境。

九,signal.h函數

signal.h頭文件中定義變量類型sig_atomic_t,兩個函數調用和幾個宏處理程序的執行過程中不同的信號報告。
*庫變量

以下是在頭signal.h中定義的變量類型:

S.N.  變量和說明
1 sig_atomic_t 
這是int型,並用作一個信號處理程序中的變量。這是一個可以被訪問的原子實體,異步信號,即使在存在一個對象,該對象的組成不同。 庫宏
以下是在頭signal.h中定義的宏,這些宏將被用在下面列出的兩個函數。信號函數SIG_宏定義信號。
S.N. 宏與說明
1 SIG_DFL
   默認信號處理程序
2 SIG_ERR
  表示一個信號錯誤。
3 SIG_IGN
  信號忽視。
  SIG宏被用來表示在下列條件下的信號數
S.N. 宏與說明
1 SIGABRT
   程序異常終止
2 SIGFPE
   除數爲零的浮點錯誤。
3 SIGILL
   非法操作。
4 SIGINT
   中斷信號,如CTRL-C。
5 SIGSEGV
   訪問無效存儲如區段違規。
6 SIGTERM
   終止請求。 

*庫函數
 以下是在頭signal.h中定義的函數:
S.N.函數及說明
void (*signal(int sig, void (*func)(int)))(int)  此功能設置函數來處理信號,即。信號處理程序。
int raise(int sig)       該函數會導致產生信號sig。信號參數是與SIG宏兼容。

十,<stdarg.h>函數

stdarg.h頭文件定義了一個變量va_list類型和三個宏,可以用來獲取一個函數的參數的個數,即不知道可變數目的參數。
可變參數函數定義的參數列表的末尾的省略號(...)。
*庫變量

以下是在頭文件stdarg.h中定義的變量類型:
S.N.變量和說明
1   va_list 
       這是一種適合於保持的信息所需要的3個宏 va_start(), va_arg() 和 va_end(). 庫宏

以下是在頭文件stdarg.h中定義的宏:
S.N. 宏與說明
1 void va_start(va_list ap, last_arg)
      此宏初始化就根據va_arg和va_end宏要使用的變量。last_arg是最後一個已知的固定參數被傳遞給函數,即。的說法前省略號。
2 type va_arg(va_list ap, type)
      這個宏檢索函數型的參數列表中的下一個參數type.
3 void va_end(va_list ap)
      這個宏允許使用va_start宏返回一個函數變量參數。 va_end中之前沒有調用的函數返回的結果是不確定的。

十一,<stddef.h>函數

stddef.h 頭文件定義了各種變量的類型和宏。許多這些定義也出現在其他頭。
*庫變量
以下是在頭stddef.h的定義的變量類型:
S.N. 變量和說明
1    ptrdiff_t
       這是有符號整數類型,是兩個指針相減的結果。
2    size_t 
       這是一個無符號整數類型的sizeof關鍵字的結果。
3    wchar_t 
       這是一個不可分割的寬字符常量的大小不同的。
*庫宏
以下是在頭stddef.h的宏定義:
S.N.宏與說明
1    NULL
       這個宏是一個空指針常量的值。
2    offsetof(type, member-designator)
       這個結果一個常數size_t類型是偏移量(以字節爲單位)的結構構件的結構從一開始的整數。構件由下式給出成員標誌符,是由於在不同的結構的名稱。

十二,<stdio.h>函數

stdio.h頭定義了三個變量的類型,幾個宏及各種功能進行輸入和輸出。
*庫變量
以下是在頭stdio.h中定義的變量類型:
S.N. 變量和說明
1  size_t 
   這是一個無符號整數類型 sizeof關鍵字的結果。
2  FILE 
   這是一個對象的類型,適合用於存儲信息的一個文件流。
3  fpos_t 
   這是一個對象類型適用於存儲在一個文件中的任何位置。 庫宏

以下是在頭stdio.h中定義的宏:
S.N. 宏與說明
1   NULL
     這個宏是一個空指針常量的值。
2 _IOFBF, _IOLBF and _IONBF 
     這些都是宏擴大整型常量表達式具有鮮明的值和適合使用setvbuf函數的第三個參數。
3 BUFSIZ
     這個宏是一個整數,它表示函數setbuf函數所使用的緩衝區的大小。
4 EOFM 
     此宏是一個負整數,表示一個結束-已到達文件結尾。
5 FOPEN_MAX 
     此宏是一個整數,代表文件的最大數目,該系統可以保證,可以同時打開。
6 FILENAME_MAX 
     這個宏是一個整數,表示一個字符數組,適合持有時間最長的可能的文件名長度最長。如果實現沒有任何限制,那麼這個值應該是推薦的最大值。
7 L_tmpnam 
     這個宏是一個整數,表示適合舉行由tmpnam函數創建的臨時文件名可能的最長的一個char數組的長度最長。
8 SEEK_CUR, SEEK_END, and SEEK_SET 
     這些宏用於的fseek 函數定位在一個文件中的不同位置。
9 TMP_MAX 
     這個宏是唯一的文件名的功能使用tmpnam可以生成的最大數量。
10 stderr, stdin, and stdout 
      這些宏的文件類型對應的標準誤差,標準輸入,標準輸出流的指針。 庫函數

以下是在頭stdio.h中定義的函數:

S.N.  函數及說明
1 void clearerr(FILE *stream)
      Clears the end-of-file and error indicators for the given stream.
2 int fclose(FILE *stream)
       Closes the stream. All buffers are flushed.
3 int feof(FILE *stream)
       Tests the end-of-file indicator for the given stream.
4 int ferror(FILE *stream)
       Tests the error indicator for the given stream.
5 int fflush(FILE *stream)
       Flushes the output buffer of a stream.
6 int fgetpos(FILE *stream, fpos_t *pos)
       Gets the current file position of the stream and writes it to pos.
7 FILE *fopen(const char *filename, const char *mode)
       Opens the filename yiibaied to by filename using the given mode.
8 size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
       Reads data from the given stream into the array yiibaied to by ptr.
9 FILE *freopen(const char *filename, const char *mode, FILE *stream)
       Associates a new filename with the given open stream and same time closing the old file in stream.
10 int fseek(FILE *stream, long int offset, int whence)
       Sets the file position of the stream to the given offset. The argument offset signifies the number of bytes to seek from the given whence position.
11 int fsetpos(FILE *stream, const fpos_t *pos)
       設置到給定位置的給定的流文件中的位置。參數pos 是由函數的fgetpos 給定的位置。
12 long int ftell(FILE *stream)
       返回給定流的當前文件位置。
13 size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
       Writes data from the array yiibaied to by ptr to the given stream.
14 int remove(const char *filename)
        Deletes the given filename so that it is no longer accessible.
15 int rename(const char *old_filename, const char *new_filename)
        Causes the filename referred to by old_filename to be changed to new_filename.
16 void rewind(FILE *stream)
        Sets the file position to the beginning of the file of the given stream.
17 void setbuf(FILE *stream, char *buffer)
         Defines how a stream should be buffered.
18 int setvbuf(FILE *stream, char *buffer, int mode, size_t size)
         Another function to define how a stream should be buffered.
19 FILE *tmpfile(void)
         Creates a temporary file in binary update mode (wb+).
20 char *tmpnam(char *str)
         Generates and returns a valid temporary filename which does not exist.
21 int fprintf(FILE *stream, const char *format, ...)
         Sends formatted output to a stream.
22 int printf(const char *format, ...)
         Sends formatted output to stdout.
23 int sprintf(char *str, const char *format, ...)
         Sends formatted output to a string.
24 int vfprintf(FILE *stream, const char *format, va_list arg)
         Sends formatted output to a stream using an argument list.
25 int vprintf(const char *format, va_list arg)
         Sends formatted output to stdout using an argument list.
26 int vsprintf(char *str, const char *format, va_list arg)
         Sends formatted output to a string using an argument list.
27 int fscanf(FILE *stream, const char *format, ...)
         Reads formatted input from a stream.
28 int scanf(const char *format, ...)
         Reads formatted input from stdin.
29 int sscanf(const char *str, const char *format, ...)
         Reads formatted input from a string.
30 int fgetc(FILE *stream)
         Gets the next character (an unsigned char) from the specified stream and advances the position indicator for the stream.
31 char *fgets(char *str, int n, FILE *stream)
         Reads a line from the specified stream and stores it into the string yiibaied to by str. It stops when either (n-1) characters are read, the newline character is read, or the end-of-file is reached, whichever comes first.
32 int fputc(int char, FILE *stream)
        Writes a character (an unsigned char) specified by the argument char to the specified stream and advances the position indicator for the stream.
33 int fputs(const char *str, FILE *stream)
        Writes a string to the specified stream up to but not including the null character.
34 int getc(FILE *stream)
        獲取下一個字符(unsigned char類型)從指定的流,並將流的指針位置。
35 int getchar(void)
        從標準輸入獲取一個字符(unsigned char類型)。
36 char *gets(char *str)
        從標準輸入讀取一行,並將其存儲到由str指向的字符串。它時停止讀取換行符或文件結束時達成,以先到爲準。
37 int putc(int char, FILE *stream)
        寫入字符到指定的流,並將流的指針位置的參數指定一個字符(unsigned char類型)。
38 int putchar(int char)
        寫一個字符(unsigned char類型)的參數指定的字符輸出到stdout。
39 int puts(const char *str)
        將一個字符串寫入到stdout,但不包括空字符。一個換行符被追加到輸出。
40 int ungetc(int char, FILE *stream)
        將字符的字符(unsigned char類型)到指定的流,這是讀取的下一字符。
41 void perror(const char *str)
        打印一個描述性的錯誤消息到stderr。首先打印字符串str接着一個冒號,然後是一個空格。

十三,<stdlib.h>函數

stdlib.h中頭文件定義了四個變量類型,用於執行一般函數的幾個宏和各類函數。
*庫變量
以下是在頭文件stdlib.h中定義的變量類型:
S.N. 變量和說明
1 size_t 
       這是一個無符號整數類型的sizeof關鍵字的結果。
2 wchar_t 
       這是一個整數類型的寬字符常量的大小。
3 div_t 
       這是結構的div函數返回。
4 ldiv_t 
       這是由 ldiv 函數返回的結構。 庫宏

以下是在頭文件stdlib.h中定義的宏:

S.N.  宏與說明
1 NULL
        這個宏是一個空指針常量的值。
2 EXIT_FAILURE
       這是退出功能,在發生故障的情況下,返回的值。
3 EXIT_SUCCESS
       這是exit函數返回成功的情況下的值。
4 RAND_MAX 
       這個宏是由rand函數傳回的最大值。
5 MB_CUR_MAX 
       這個宏不能大於MB_LEN_MAX的多字節字符集的最大字節數。 庫函數

以下是在頭stdio.h中定義的函數:

S.N. 功能及說明

1 double atof(const char *str)
        轉換參數str指向的字符串到浮點數(double類型)。
2 int atoi(const char *str)
        轉換參數str指向的字符串爲整數(int型)。
3 long int atol(const char *str)
        轉換字符串參數str指向一個長整型(類型爲long int)
4 double strtod(const char *str, char **endptr)
        轉換參數str指向的字符串到浮點數(double類型)。
5 long int strtol(const char *str, char **endptr, int base)
        字符串轉換成一個長整型(類型爲long int)參數str指向。
6 unsigned long int strtoul(const char *str, char **endptr, int base)
        轉換字符串參數str指向一個無符號長整型(unsigned long型整數)。
7 void *calloc(size_t nitems, size_t size)
        分配請求的內存,並返回一個指向它的指針。
8 void free(void *ptr
        calloc,malloc或realloc調用先前分配的回收內存。
9 void *malloc(size_t size)
        Allocates the requested memory and returns a yiibaier to it.
10 void *realloc(void *ptr, size_t size)
        嘗試調整的內存塊的大小由ptr指向先前調用malloc或calloc的分配。
11 void abort(void)
        導致程序異常終止。
12 int atexit(void (*func)(void))
        導致指定的函數功能,當程序正常終止時,被調用。
13 void exit(int status)
        導致正常程序終止。
14 char *getenv(const char *name)
        name所指向環境字符串的搜索,並返回相關的字符串的值。
15 int system(const char *string)
        字符串指定的命令被傳遞到主機環境中,要執行的命令處理器。
16 void *bsearch(const void *key, const void *base, size_t nitems, size_t size, int (*compar)(const void *, const void *))
        執行二進制搜索。
17 void qsort(void *base, size_t nitems, size_t size, int (*compar)(const void *, const void*))
        對數組排序
18 int abs(int x)
        返回x的絕對值。
19 div_t div(int numer, int denom)
        數(分子numer)除以分母(分母denom)。
20 long int labs(long int x)
        返回x的絕對值。
21 ldiv_t ldiv(long int numer, long int denom)
        數(分母denom)除以分母(分子numer)。
22 int rand(void)
        返回一個取值範圍爲0到RAND_MAX之間的僞隨機數。
23 void srand(unsigned int seed)
        這個函數使用rand函數隨機數生成器的種子。
24 int mblen(const char *str, size_t n)
        返回參數str指向一個多字節字符的長度。
25 size_t mbstowcs(schar_t *pwcs, const char *str, size_t n)
        轉換pwcs 指向的數組參數str所指向的多字節字符的字符串。 
26 int mbtowc(whcar_t *pwc, const char *str, size_t n)
        檢查參數str所指向的多字節字符。
27 size_t wcstombs(char *str, const wchar_t *pwcs, size_t n)
        存儲在數組pwcs  多字節字符並存入字符串str中的代碼轉換。
28 int wctomb(char *str, wchar_t wchar)
        檢查參數wchar多字節字符對應的代碼。 

十四,<string.h>函數

string.h 頭定義了一個變量的類型,操作字符數組的一個宏觀和各種功能。
*庫變量
以下是在頭string.h中定義的變量類型:
S.N. 變量和說明
1 size_t 
這是一個無符號整數類型的sizeof關鍵字的結果。 庫宏
以下是在頭string.h中定義的宏:

S.N. 宏觀與說明
1 NULL
這個宏是一個空指針常量的值。 庫函數
以下是頭string.h中定義的功能:

S.N. 函數及說明
1 void *memchr(const void *str, int c, size_t n)
        搜索第一次出現的字符c(unsigned char類型)的前n個字節的字符串參數str指向。
2 int memcmp(const void *str1, const void *str2, size_t n)
        比較str1和str2的前n個字節。
3 void *memcpy(void *dest, const void *src, size_t n)
       從src複製n個字符到dest。
4 void *memmove(void *dest, const void *src, size_t n)
       另一個函數來複制n個字符到str1。
5 void *memset(void *str, int c, size_t n)
       複製字符c(unsigned char類型)的前n個字符的字符串參數str指向。
6 char *strcat(char *dest, const char *src)
       追加src指向的字符串到dest指向的字符串的結束。
7 char *strncat(char *dest, const char *src, size_t n)
       追加src指向字符串結尾的字符串指向dest中最多n個字符長。
8 char *strchr(const char *str, int c)
       搜索第一次出現的字符串中的字符c(unsigned char類型)參數str指向。
9 int strcmp(const char *str1, const char *str2)
       比較字符串str1指向指向的字符串str2。
10 int strncmp(const char *str1, const char *str2, size_t n)
       str1和str2的前n個字節相比。
11 int strcoll(const char *str1, const char *str2)
       比較字符串str1的STR2。其結果是依賴於位置LC_COLLATE設置。
12 char *strcpy(char *dest, const char *src)
      複製字符串src指向到dest。
13 char *strncpy(char *dest, const char *src, size_t n)
      副本最多n個字符的字符串src指向到dest。
14 size_t strcspn(const char *str1, const char *str2)
      計算str1的起始段的長度完全包含在str2中的字符。
15 char *strerror(int errnum)
      搜索一個內部數組的錯誤編號差錯編號,並返回一個指向一個錯誤消息字符串。
16 size_t strlen(const char *str)
      計算但不包括終止空字符的字符串str的長度。
17 char *strpbrk(const char *str1, const char *str2)
      查找字符串str1在str2中指定的任何字符相匹配的第一個字符。
18 char *strrchr(const char *str, int c)
      參數str指向的字符串中的字符c(unsigned char類型)最後一次出現的搜索。
19 size_t strspn(const char *str1, const char *str2)
      計算str1中的初始段完全包含在str2中的字符的長度。
20 char *strstr(const char *haystack, const char *needle)
      查找第一次出現的整個字符串針(不包括終止空字符)出現在字符串haystack中。
21 char *strtok(char *str, const char *delim)
      中斷字符串str分隔分離成一系列的記號。
22 size_t strxfrm(char *dest, const char *src, size_t n)
      轉換前n個字符的字符串src到校報的語言環境和將它們放置字符串dest。

十五,<time.h>函數

time.h 頭定義了四個變量類型,兩個宏和用於操作的日期和時間的各種功能。
*庫變量
 以下是在頭time.h中定義的變量類型:
 S.N.變量和說明
 1size_t 
        這是一個無符號整數類型的sizeof關鍵字的結果。
 2clock_t 
        這是一種適合用於存儲處理器的時間。
 3time_t is 
        這是一種適合用於存儲日曆時間。
 4struct tm 
        這是一個結構,用於保存的時間和日期。
tm結構具有下列定義:
struct tm {
   int tm_sec;         /* seconds,  range 0 to 59          */
   int tm_min;         /* minutes, range 0 to 59           */
   int tm_hour;        /* hours, range 0 to 23             */
   int tm_mday;        /* day of the month, range 1 to 31  */
   int tm_mon;         /* month, range 0 to 11             */
   int tm_year;        /* The number of years since 1900   */
   int tm_wday;        /* day of the week, range 0 to 6    */
   int tm_yday;        /* day in the year, range 0 to 365  */
   int tm_isdst;       /* daylight saving time             */
};
*庫宏
以下是在頭time.h中定義的宏:
S.N. 宏觀與說明
1NULL
        這個宏是一個空指針常量的值。
2CLOCKS_PER_SEC 
        這個宏表示每秒的處理器時鐘週期的數目。 庫函數

以下是在頭time.h中定義的函數:
S.N. 函數及說明
1 char *asctime(const struct tm *timeptr)
       將指針返回到一個字符串,它表示結構timeptr 日期和時間。
2 clock_t clock(void)
       返回處理器的時鐘使用,因爲一個實現定義的時代的開始(通常是程序開頭)。
3 char *ctime(const time_t *timer)
       返回一個字符串,代表localtime基於參數定時器。
4 double difftime(time_t time1, time_t time2)
       返回秒時間1和時間2(時間1時間2)之間的差值。
5 struct tm *gmtime(const time_t *timer)
       定時器的值被分解成結構tm表示以協調通用時間(UTC),也被稱爲格林威治標準時間(GMT)。
6 struct tm *localtime(const time_t *timer)
       定時器的值被分解成結構tm表示本地時區。
7 time_t mktime(struct tm *timeptr)
       結構轉換所指出timeptr成一個time_t值,根據本地時區。
8 size_t strftime(char *str, size_t maxsize, const char *format, const struct tm *timeptr)
       格式結構timeptr根據定義格式並存儲到str格式規則表示的時間。
9 time_t time(time_t *timer)
       計算當前壓延時間,並將其編碼成time_t的格式。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章