C库函数 - ctime()
C库函数 - ctime() #include <stdio.h> #include <time.h> int main () { time_t curtime; time(&curtime); printf("Current time = %s", ctime(&curtime)); return(0); }
阅读全文 ↗C库函数 - ctime() #include <stdio.h> #include <time.h> int main () { time_t curtime; time(&curtime); printf("Current time = %s", ctime(&curtime)); return(0); }
阅读全文 ↗C库函数 - clock() #include <time.h> #include <stdio.h> int main () { clock_t start_t, end_t, total_t; int i; start_t = clock(); printf("Starting of the program, start_t = %ld\n", start_t); printf("Going to scan a big loop, start_t = %ld\n", start_t); for(i=0; i< 10000000; i++) { } end_t = clock(); printf("End of the big loop, end_t = %ld\n", end_t); total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC; printf("Total time taken by CPU: %f\n", total_t ); printf("Exiting of the program...\n"); return(0); }
阅读全文 ↗C库函数 - asctime() #include <stdio.h> #include <string.h> #include <time.h> int main () { struct tm t; t.tm_sec = 10; t.tm_min = 10; t.tm_hour = 6; t.tm_mday = 25; t.tm_mon = 2; t.tm_year = 89; t.tm_wday = 6; puts(asctime(&t)); return(0); }
阅读全文 ↗C库函数 - strxfrm() #include <stdio.h> #include <string.h> int main () { char dest[20]; char src[20]; int len; strcpy(src, "Tutorials Point"); len = strxfrm(dest, src, 20); printf("Length of string |%s| is: |%d|", dest, len); return(0); }
阅读全文 ↗C库函数 - strtok() #include <string.h> #include <stdio.h> int main () { char str[80] = "This is - www.codingdict.com - website"; const char s[2] = "-"; char *token; /* get the first token */ token = strtok(str, s); /* walk through other tokens */ while( token != NULL ) { printf( " %s\n", token ); token = strtok(NULL, s); } return(0); }
阅读全文 ↗C库函数 - strstr() #include <stdio.h> #include <string.h> int main () { const char haystack[20] = "codingdict"; const char needle[10] = "Point"; char *ret; ret = strstr(haystack, needle); printf("The substring is: %s\n", ret); return(0); }
阅读全文 ↗C库函数 - strspn() #include <stdio.h> #include <string.h> int main () { int len; const char str1[] = "ABCDEFG019874"; const char str2[] = "ABCD"; len = strspn(str1, str2); printf("Length of initial segment matching %d\n", len ); return(0); }
阅读全文 ↗C库函数 - strrchr() #include <stdio.h> #include <string.h> int main () { int len; const char str[] = "http://www.codingdict.com"; const char ch = '.'; char *ret; ret = strrchr(str, ch); printf("String after |%c| is - |%s|\n", ch, ret); return(0); }
阅读全文 ↗C库函数 - strpbrk() #include <stdio.h> #include <string.h> int main () { const char str1[] = "abcde2fghi3jk4l"; const char str2[] = "34"; char *ret; ret = strpbrk(str1, str2); if(ret) { printf("First matching character: %c\n", *ret); } else { printf("Character not found"); } return(0); }
阅读全文 ↗C库函数 - strlen() #include <stdio.h> #include <string.h> int main () { char str[50]; int len; strcpy(str, "This is codingdict.com"); len = strlen(str); printf("Length of |%s| is |%d|\n", str, len); return(0); }
阅读全文 ↗C库函数 - strerror() #include <stdio.h> #include <string.h> #include <errno.h> int main () { FILE *fp; fp = fopen("file.txt","r"); if( fp == NULL ) { printf("Error: %s\n", strerror(errno)); } return(0); }
阅读全文 ↗C库函数 - strcspn() #include <stdio.h> #include <string.h> int main () { int len; const char str1[] = "ABCDEF4960910"; const char str2[] = "013"; len = strcspn(str1, str2); printf("First matched character is at %d\n", len + 1); return(0); }
阅读全文 ↗