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; } /* 运行结果 无<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; } /* 运行结果 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; } /* 运行结果 ----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; } /* 运行结果 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; } /* 运行结果 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' の前の定義を確認してください Microsoft (R) Incremental Linker Version 6.00.8168 Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
返回