gpt4 book ai didi

c - C 中的 strtok 错误

转载 作者:太空宇宙 更新时间:2023-11-04 07:17:16 25 4
gpt4 key购买 nike

<分区>

我有这么一小段代码:

int* index=(int*)(sizeof(int)*NB);
while(i < NB){
printf("i=%d, pch=%s\n", i, pch);
if (strcmp(pch, SPLIT_PATTERN))
i++;
else
index[k++]=i-1;
pch = strtok(NULL, "-");
}

并使用此输入:

file_content EN7FSQcL63NRUQHSBBRDtVUkobmStQbKdL2cR7gpoC5-X2rS1Cu2RCYaw0TiGdYUUtYuCTB5WlE9Y3SJNuiimQC-ajksldnalmcjlakjflksjoi-
NB = 2
SPLIT_PATTERN = ajksldnalmcjlakjflksjoi (the last part in file_content)

C 给我段错误。

i=0, pch=EN7FSQcL63NRUQHSBBRDtVUkobmStQbKdL2cR7gpoC5
i=1, pch=X2rS1Cu2RCYaw0TiGdYUUtYuCTB5WlE9Y3SJNuiimQC
Segmentation fault (core dumped)

请告诉我哪里做错了?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com