我正在尝试创建一个函数来替换单词。它还支持用户输入的多个参数(单词)。例如,我们有一个名为“fesf”的文本文件,其中包含以下内容:“这是一个测试。”当我们键入
./a.out test is < fesf.txt
它应该在fesf.txt中用“censor”替换“test”和“is”。 (请注意,新行、排列应与原始文件相同,只有单词被替换)。我创建了这个函数,但不知何故它不起作用。返回时,它不会替换参数,只会打印原始文本。
以下是该函数:
./a.out test is < fesf.txt
它应该在fesf.txt中用“censor”替换“test”和“is”。 (请注意,新行、排列应与原始文件相同,只有单词被替换)。我创建了这个函数,但不知何故它不起作用。返回时,它不会替换参数,只会打印原始文本。
以下是该函数:
#include <stdio.h>
#include <string.h>
int main (int argc, char* argv[])
{
int i, j,c, state, wordlen, counter, found;
char word[128];
state = 0;
wordlen = 0;
while (( c= getchar())!= EOF) {
if ((c >= 'A' && c <= 'Z') || (c == 39))
{
state =1;
word[wordlen] = c;
wordlen++;
}
else if (state == 1)
{
state =0;
found =0;
}
isalpha(c) || c == 39
。但是´
有什么特别之处呢? - EOF