我正在使用的代码:
char** list
char** final;
char* target;
char* replace;
int wCounter, cCounter, i, hashCounter = 0, addLetter = 0;
int copyWord, countChars, numOfWords, finalWords = 0, temp;
//stuff here
for(wCounter; wCounter < temp + numOfWords; wCounter++, finalWords++)
{
printf("Original string: %s\n", list[wCounter+1]);
final[finalWords] = strstr(list[wCounter+1], target);
if(final[finalWords] != NULL)
memcpy(final[finalWords], replace, strlen(target));
printf("Final string: %s\n\n", final[finalWords]);
}
//stuff here
我的程序输出:
Target string = h Replacement string = j
Original string: hello
Final string: jello //works!!!
Original string: happy birthday
Final string: jappy birthday // should be jappy birtjday
Target string = ra Replacement string = ar
Original string: radar
Final string: ardar //works!!!
Original string: are you ready
Final string: (null) //awkward
Original string: pirate radio rating
Final string: arte radio rating //should be piarte ardio arting
Target string = x Replacement string = zz
Original string: exit
Final string: zit //should be zzit
Original string: x-ray
Final string: z-ray //should be zz-ray
Original string: xerox
Final string: zerox //should be zzerox
我的程序有一个目标字符串(例如'h')它还有一个替换字符串(例如'j')
每次它看到一个'h'它应该用'j'替换它
生日快乐应该是 jappy birtjday。