標籤:ret const enc 超過 tran 字元 imu starting span
strchr函數與strrchr函數
1 Action() 2 { 3 // strchr函數用於尋找指定字元在一個字串中第1次出現的位置,然後返回指向該位置的指標; 4 // strrchr函數使用者尋找指定字元在一個字串中最後1次出現的位置,然後返回指向該位置的指標。 5 // 文法結構 6 // char *strchr(const char *string,int c); 7 // char *strrchr(const char *string,int c); 8 9 10 char *string = "I‘m a young soul in this very strange world";11 char *first_a, *last_a;12 13 first_a = (char *)strchr(string, ‘a‘);14 lr_output_message("The first occurrence of a: %s", first_a);15 16 last_a = (char *)strrchr(string, ‘a‘);17 lr_output_message("The last occurrence of a: %s", last_a);18 19 return 0;20 }21 -----------------------------------------------------------------------------------22 Running Vuser...23 Starting iteration 1.24 Maximum number of concurrent connections per server: 6 [MsgId: MMSG-26989]25 Starting action Action.26 Action.c(14): The first occurrence of a: a young soul in this very strange world27 Action.c(17): The last occurrence of a: ange world28 Ending action Action.29 Ending iteration 1.30 Ending Vuser...
strcpy函數與strncpy函數
1 Action() 2 { 3 // strcpy函數是把一個字串複製到另一個字串中; 4 // strncpy函數是把一個字串中的指定長度複製到另一個字串中,如果指定長度超過了字串長度,則會複製整個字串。 5 // 文法結構 6 // strcpy: char *strcpy(char *dest, const char *source); 7 // strncpy: char *strncpy(char *dest,const char *source, size_t n); 8 // 參數dest是目標字串,source是源字串,n是要複製的長度。 9 10 11 char test[50];12 char ntest[50];13 strcpy(test, "Copies one string to another.");14 lr_output_message("%s", test);15 16 strncpy(ntest, "Copies the first n characters of one string to another?", 30);17 lr_output_message("%s", ntest);18 19 return 0;20 }21 22 ----------------------------------------------------------------------------------23 Running Vuser...24 Starting iteration 1.25 Maximum number of concurrent connections per server: 6 [MsgId: MMSG-26989]26 Starting action Action.27 Action.c(14): Copies one string to another.28 Action.c(17): Copies the first n characters 29 Ending action Action.30 Ending iteration 1.31 Ending Vuser...
Vuser中常用的C語言函數