这里为什么会多个引号呢? 明明两次都是拼接的"非"
源码:
#include <stdio.h>
#include <string.h>
#define SENT_LEN 5
#define WORDS_NUM 2
#define STR_LEN 101
int main(int argc, char** argv)
{
int i, j;
char words[SENT_LEN][STR_LEN] = {"非","淡泊","无以","明志","!"};
char source[WORDS_NUM][STR_LEN] = {"淡泊","明志"};
char target[WORDS_NUM][STR_LEN] = {"宁静","致远"};
char sentence_before[STR_LEN];
char sentence_after[STR_LEN];
for (i = 0; i < SENT_LEN; ++i)
{
strcat(sentence_before, words[i]);
for (j = 0; j < WORDS_NUM; ++j)
if (strcmp(words[i], source[j]) == 0)
strcpy(words[i], target[j]);
strcat(sentence_after, words[i]);
}
puts("替换前:");
puts(sentence_before);
puts("替换后:");
puts(sentence_after);
return 0;
}