标记字符串中所有出现的子字符串

时间:2018-12-02 01:52:28

标签: c

如何实现标记字符串中所有出现的子字符串?

这是我到目前为止获得的代码。

char *tmp = line;
int count = 0;
while ((tmp = strstr2(tmp, argv[2])) != NULL) {
    int start = (int) (tmp - line);
    count += start;
    printf("%.*s", count, line);
    printf(">" %.*s" "<", strlen2(argv[2]), line + start);
}
printf("\n");

例如,在字符串“ hehe xd hehe xd” 中,如果我正在搜索“ xd” ,我希望输出看起来像“ hehe> xd xd <“

显然行不通,但我坚持这一点,无法提出其他解决方案。

我只能使用<stdio.h><stdlib.h>标头中的工具。

0 个答案:

没有答案