有关字符串逆续处理?

来源:百度知道 编辑:UC知道 时间:2024/09/23 14:39:43
例子: you he,me
this is a c program
处理后: me he you
program c a is this
假设已经在一个程序中调用了一篇英文文章,按照每行进行处理,用c语言怎么编写子程序啊?
哪位大哥帮一下忙吧,感激不尽........
he和么之间的是逗号,还有更为简单点方法吗?

单个读取字符 全部存储到字符数组中 然后用strrev函数反序排列
或者用 指针数组

这个he,me中间是逗号还是空格啊?
要是逗号的话就题就麻烦了,对于C来讲恐怕要一个字符一个字符的判断处理了。
如果是空格的话好办一些,写个参考程序:

#include<stdio.h>
#include<string.h>
int Solve(char *filein,char *fileout)
{
FILE *fpin,*fpout;
char word[100][100];
int index;
if((fpin=fopen(filein,"r"))==NULL||(fpout=fopen(fileout,"w"))==NULL)
{
printf("cann't open file!");
return -1;
}
else
{
while(!feof(fpin))
{
index=0;
do
{
fscanf(fpin,"%s",word[index]);
index++;
}while(fgetc(fpin)!='\n'&&!feof(fpin));
while(index>0)
{
index--; fprintf(fpout,"%s",word[index]);
if(index!=0)
fputc(' ',fpout);
else fputc('\n',fpout); }
}
fclose(fpin);
fclose(fpout);
}
}
void main