C ทำงานห้องสมุด - strtok ()
ลักษณะ
C ทำงานห้องสมุดchar * strtok (char * Str, const char * delim) ย่อยสลายเป็นชุดของสตริง STR ที่delim เป็นตัวคั่น
คำแถลง
นี่คือ () ฟังก์ชัน strtok คำสั่ง
char *strtok(char *str, const char *delim)
พารามิเตอร์
- STR - ที่จะแบ่งออกเป็นชุดของสตริงของสตริงขนาดเล็ก
- ซีสตริงที่มีตัวคั่น- delim
ราคาย้อนกลับ
ฟังก์ชั่นนี้จะส่งกลับสตริงย่อยสลายที่ผ่านมาหากไม่มีสตริงการค้นหาก็จะส่งกลับตัวชี้โมฆะ
ตัวอย่าง
ตัวอย่างต่อไปนี้แสดงให้เห็นถึง strtok () ฟังก์ชั่นถูกนำมาใช้
#include <string.h> #include <stdio.h> int main() { const char str[80] = "This is - www.w3cschool.cc - website"; const char s[2] = "-"; char *token; /* 获取第一个子字符串 */ token = strtok(str, s); /* 继续获取其他的子字符串 */ while( token != NULL ) { printf( " %s\n", token ); token = strtok(NULL, s); } return(0); }
Let 's รวบรวมและเรียกใช้โปรแกรมข้างต้นซึ่งจะส่งผลต่อไปนี้:
This is www.w3cschool.cc website