如何实现标记字符串中所有出现的子字符串?
这是我到目前为止获得的代码。
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
显然行不通,但我坚持这一点,无法提出其他解决方案。
我只能使用<stdio.h>
和<stdlib.h>
标头中的工具。