|
发表于 2004-1-19 20:18:10
|
显示全部楼层
这是我写的代码,我不是很清楚你的具体要求,但最关键的东西已经表示出来了。你完全可以在这个基础上进行修改以满足你的需要。
用法:把程序用gcc编译好之后,直接执行,根据提示先后输入文本文件名和输出文件名,输出文件中的内容即是执行结果。
[php]
#include<stdio.h>
int main(int argc, char* argv[])
{
FILE *in, *out;
char file_in[50], file_out[50];
char c1, c2;
/* tell program about the filename and open it. */
printf("%s\n", "input the filename of text file:");
scanf("%s", file_in);
in = fopen(file_in, "r");
printf("\n%s\n", "input the filename of output file:");
scanf("%s", file_out);
out = fopen(file_out, "w");
c1 = fgetc(in);
while ( (c2 = fgetc(in) ) != EOF ) {
if (c1 >= 'a' && c1 <= 'z') {
if ( c1 == c2 )
fputc(c1, out);
else {
fputc(c1, out);
fputc(',', out);
}
}
c1 = c2;
}
}
[/php] |
|