gpt4 book ai didi

c - 在字符串中搜索字符串

转载 作者:行者123 更新时间:2023-11-30 19:57:43 25 4
gpt4 key购买 nike

我有:"ETSGYU-deDEGUw<div>TOTO/$$/hfuiehfurei"我想在"<div>"之后获得链条和之前"/$$/"然后:"TOTO"

int main (int argc, char* argv[])
{
char IN[1000];
char OUT[1000];
strcpy(IN,"ETSGYU-deDEGUw<div>TOTO/$$/hfuiehfurei");

...

printf("%s\n",OUT);
}

致以诚挚的问候

最佳答案

使用strstr() @pm100 .

为了不向您提供所有代码,请使用以下大纲。 OP 仍然需要确定 4 个 ... 部分。

int main(int argc, char* argv[]) {
char IN[1000];
//char OUT[1000];
strcpy(IN, "ETSGYU-deDEGUw<div>TOTO/$$/hfuiehfurei");
const char *pattern1 = "<div>";
const char *pattern2 = "/$$/";
char *start = strstr(IN, pattern1);
if (start) {

// Increase `start` by the length of `pattern1`
start += ...;

// Search again, this time for pattern2. From where should searching start?
char *end = ...;

if (end) {

// print from start. Only need to print some of the characters
int length = ...
printf("%.*s\n", ...);

return 0;
}
}
puts("Fail");
return -1;
}

关于c - 在字符串中搜索字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38593981/

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