我正在 C 上制作我自己的 Strtok 版本。
我幾乎完成了,但是,我在互聯網上找到了我需要的最后一部分,但我真的不明白它的作用。最終我實際上得到了它的作用,但仍然不明白它為什么起作用。我缺乏理論;(
char* strtok_sad(char* str, const char* delim) {
static char* next = 0;
if (str) {
next = str;
}
if (*next == 0) {
return NULL;
}
char* c = next;
while(strchr(delim,*c)) {
c;
}
if (*c == 0) {
return NULL;
}
char* word = c;
while(strchr(delim,*c)==0) {
c;
}
if (*c == 0) {
next = c;
return word;
}
*c = 0;
next = c 1;
return word;
}
有人可以解釋這部分,或者至少給我發一篇解釋它的文章:
*c = 0;
next = c 1;
謝謝!
uj5u.com熱心網友回復:
我將回答所問問題的非主題版本/部分。
*c = 0;無論c指向什么,都設定為 0 。next = c 1;讓人next落后一分c。我假設您可以發現這種重新措辭和strtok().
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/378633.html
上一篇:C編程回傳0
下一篇:為什么我們用絕對值來求余弦級數?
