C库函数 - exit() #include <stdio.h> #include <stdlib.h> int main () { printf("Start of the program....\n"); printf("Exiting the program....\n"); exit(0); printf("End of the program....\n"); return(0); }
C库函数 - atexit() #include <stdio.h> #include <stdlib.h> void functionA () { printf("This is functionA\n"); } int main () { /* register the termination function */ atexit(functionA ); printf("Starting main program...\n"); printf("Exiting main program...\n"); return(0); }
C库函数 - abort() #include <stdio.h> #include <stdlib.h> int main () { FILE *fp; printf("Going to open nofile.txt\n"); fp = fopen( "nofile.txt","r" ); if(fp == NULL) { printf("Going to abort the program\n"); abort(); } printf("Going to close nofile.txt\n"); fclose(fp); return(0); }
C库函数 - strtoul() #include <stdio.h> #include <stdlib.h> int main () { char str[30] = "2030300 This is test"; char *ptr; long ret; ret = strtoul(str, &ptr, 10); printf("The number(unsigned long integer) is %lu\n", ret); printf("String part is |%s|", ptr); return(0); }
C库函数 - strtol() #include <stdio.h> #include <stdlib.h> int main () { char str[30] = "2030300 This is test"; char *ptr; long ret; ret = strtol(str, &ptr, 10); printf("The number(unsigned long integer) is %ld\n", ret); printf("String part is |%s|", ptr); return(0); }
C库函数 - strtod() #include <stdio.h> #include <stdlib.h> int main () { char str[30] = "20.30300 This is test"; char *ptr; double ret; ret = strtod(str, &ptr); printf("The number(double) is %lf\n", ret); printf("String part is |%s|", ptr); return(0); }
C库函数 - atol() #include <stdio.h> #include <stdlib.h> #include <string.h> int main () { long val; char str[20]; strcpy(str, "98993489"); val = atol(str); printf("String value = %s, Long value = %ld\n", str, val); strcpy(str, "codingdict.com"); val = atol(str); printf("String value = %s, Long value = %ld\n", str, val); return(0); }