?C???,?????????sscanf()
?????????????????????????sscanf()
???????:
#includeint main() { char str[] = "Hello, World! This is a test string."; char subtr[20]; // ????????? int start_index = 7; // ????????? int length = 5; // ??????? sscanf(str + start_index, " s", subtr); // ?????????????? printf("The sub string is: %s\n", subtr); return 0; }
??????,????sscanf()
???str
??????????7??????5??????
??????????????????,??????????:
#includevoid substring(char s[], int start, int len, char sub[]) { int i; for (i = 0; i < len && s[start + i] != '\0'; i++) { sub[i] = s[start + i]; } sub[i] = '\0'; } int main() { char str[] = "Hello, World! This is a test string."; char subtr[20]; // ????????? int start_index = 7; // ????????? int length = 5; // ??????? substring(str, start_index, length, subtr); printf("The sub string is: %s\n", subtr); return 0; }
???????????????substring()
????????