常用的系统函数
#include <stdio.h>
#include <string.h> // 頭文件中聲明字符串相關的系統函數void main() {char src[50] = "abc", dest[50]; //定義了兩個字符數組(字符串) , 大小為50char * str = "abcdff";printf("str.len=%d", strlen(str)); //統計字符串的大小//表示將 "hello" 拷貝到 src//注意,拷貝字符串會將原來的內容覆蓋strcpy(src, "hello");printf("\s src=%s", src); strcpy(dest, "代止兮");//strcat 是將 src 字符串的內容連接到 dest ,但是不會覆蓋dest原來的內容,而是連接!! strcat(dest, src); // "hello代止兮"printf("最終的目標字符串: dest=%s", dest);getchar();}
#include <stdio.h> #include <time.h> //該頭文件中,聲明和日期和時間相關的函數void test() { // 運行test函數,看看執行花費時間int i = 0;int sum = 0;int j = 0;for(i = 0; i < 77777777;i++) {sum = 0;for (j = 0; j< 10;j++) {sum += j;}} }int main () {//time_t curtime; //time_t 是一個結構體類型//time(&curtime); //time() 完成初始化ctime 返回一個表示當地時間的字符串,當地時間是基于參數 timer//printf("當前時間 = %s", ctime(&curtime));//getchar();//return(0);//先得到執行test前的時間time_t start_t, end_t;double diff_t; //存放時間差printf("程序啟動...\n");time(&start_t); //初始化得到當前時間test(); //執行test//再得到執行test后的時間time(&end_t);//得到當前時間diff_t = difftime(end_t, start_t); //時間差,按秒 ent_t - start_t//然后得到兩個時間差就是耗用的時間printf("執行test()函數 耗用了%.2f 秒", diff_t);getchar();return 0; }
#include <stdio.h> #include <time.h> //該頭文件中,聲明和日期和時間相關的函數void test() { // 運行test函數,看看執行花費時間int i = 0;int sum = 0;int j = 0;for(i = 0; i < 77777777;i++) {sum = 0;for (j = 0; j< 10;j++) {sum += j;}} }int main () {//time_t curtime; //time_t 是一個結構體類型//time(&curtime); //time() 完成初始化ctime 返回一個表示當地時間的字符串,當地時間是基于參數 timer//printf("當前時間 = %s", ctime(&curtime));//getchar();//return(0);//先得到執行test前的時間time_t start_t, end_t;double diff_t; //存放時間差printf("程序啟動...\n");time(&start_t); //初始化得到當前時間test(); //執行test//再得到執行test后的時間time(&end_t);//得到當前時間diff_t = difftime(end_t, start_t); //時間差,按秒 ent_t - start_t//然后得到兩個時間差就是耗用的時間printf("執行test()函數 耗用了%.2f 秒", diff_t);getchar();return 0; }
總結
- 上一篇: 增强for
- 下一篇: 系统模块——什么是系统模块、path 路