stdlib.h

返回

stdlib.h

#include <stdio.h> #include <stdlib.h> int main(void) { double ddt; char ss[] = "78999.8"; ddt = atof(ss); printf("%f\n", ddt); return 0; } /* 運行結(jié)果 無<stdlib.h>時 4230120.000000 有<stdlib.h>時 78999.800000 */

stdlib.h,srand

#include <stdio.h> #include <stdlib.h> int main(void) { unsigned sd; printf("Please input one number:"); scanf("%d", &sd); srand(sd); printf("sd=%d",sd); return 0; } /* 運行結(jié)果 Please input one number:44 sd=44 */

stdlib.h,abort

#include <stdio.h> #include <stdlib.h> /* for abort */ #include <signal.h> int mystatus; void myhandle(int sig) { printf("Signal %d started.\n", sig); printf("status=%d, the program stopped.\n", mystatus); printf("Please ask question with the NO.\n"); } int main(void) { signal(SIGABRT, myhandle); mystatus = 1234; puts("----abort Front"); abort(); puts("----abort After"); return 0; } /* 運行結(jié)果 ----abort Front abnormal program termination Signal 22 started. status=1234, the program stopped. Please ask question with the NO.BUFSIZ=512 abcdefghijABCDEFGHIJ */

stdlib.h,malloc,realloc

#include <stdio.h> #include <stdlib.h> #include <string.h> void memput(char *p, int n) { int i; for (i=0; i<n; i++) putchar(*p++); putchar('\n'); } int main(void) { char *p1, *p2, *p3; p1 = (char *)malloc(100); strcpy(p1, "abcdefghij"); memput(p1, 10); p2 = (char *)realloc(p1, 200); memput(p2, 10); p3 = (char *)realloc(p2, 5); memput(p3, 6); return 0; } /* 運行結(jié)果 abcdefghij abcdefghij abcdef */

stdlib.h,rand

#include <stdio.h> #include <stdlib.h> #define RAND_MAX 0x7fff; main(void) { double rand1; rand1 = rand(); printf ("rand1=%f\n",rand1); return 0; } /* 運行結(jié)果 rand1=41.000000 */ /* Maximum value that can be returned by the rand function. */ #define RAND_MAX 0x7fff #define RAND_MAX 0x7fff; test090302.c(4) : warning C4005: 'RAND_MAX' : ???が再定義されました。 C:\Program Files\Microsoft Visual Studio\VC98\include\stdlib.h(129) : 'R AND_MAX' の前の定義を確認(rèn)してください Microsoft (R) Incremental Linker Version 6.00.8168 Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
返回
牡丹江市| 临洮县| 济阳县| 玛纳斯县| 浦东新区| 普安县| 龙南县| 嘉义市| 葵青区| 旺苍县| 敦煌市| 贵定县| 正安县| 明光市| 根河市| 城市| 神农架林区| 陆川县| 三亚市| 长沙县| 吉木乃县| 沐川县| 北川| 清流县| 建水县| 前郭尔| 海阳市| 天全县| 广安市| 乃东县| 辛集市| 永康市| 冷水江市| 临潭县| 阜城县| 哈尔滨市| 景宁| 民丰县| 都兰县| 合山市| 莱芜市|