C语言关于字符处理类型的题目,求解答,谢谢!!

函数ReadDat()实现从文件IN.DAT中读取一篇英文文章存入到字符串数组xx中;请编制函数StrOR(),其函数的功能是:以行为单位依次把字符串中所有小写字母o左边... 函数ReadDat( )实现从文件IN.DAT中读取一篇英文文章存入到字符串数组xx中;请编制函数StrOR( ),其函数的功能是:以行为单位依次把字符串中所有小写字母o左边的字符串内容移到该串的右边存放,然后把小写字母o删除,余下的字符串内容移到已处理字符串的左边存放,之后把已处理的字符串仍按行重新存入字符串数组xx中。最后main()函数调用函数WriteDat()把结果xx输出到文件OUT5.DAT中
void StrOR(void)
{int i,righto,j,s,k;
char tem[80];
for(i=0;i<maxline;i++)
for(j=strlen(xx[i])-1;j>=0;j--)
{ k=0;
memset(tem,0,80);//初始化数组tem;
if(xx[i][j]=='o')
{righto=j;
for(s=righto+1;s<strlen(xx[i]);s++)
tem[k++]=xx[i][s];
for(s=0;s<righto;s++)
if(xx[i][s]!='o') 防止第一个就是O的情况下!
tem[k++]=xx[i][s];
strcpy(xx[i],tem);
}
else
continue;
}

我看完后觉得如果一行中如果有多个‘o’那怎么办???
展开
 我来答
paniarch
2013-08-21 · TA获得超过288个赞
知道小有建树答主
回答量:207
采纳率:0%
帮助的人:152万
展开全部

有多个分开的o的话,那最后一个o后面的字符串放最前,前面的去掉o放后面

看下这个是不是你想要的。。。。。。

   void remove_o(char * str)
   {
           char * tmp = strdup(str);
           int i,j=0;
           char * lasto = strrchr(str, 'o');

           if (lasto == NULL)
                   return;

           *lasto = 0;
           lasto++;
           strcpy(tmp, lasto);
           j = strlen(tmp);
           int n = strlen(str);
           for (i = 0; i<n; i++)
                   if (str[i] != 'o')
                           tmp[j++] = str[i];
           tmp[j++] = 0;

           strcpy(str, tmp);
           free(tmp);
   }
奇忧幻
推荐于2016-05-03
知道答主
回答量:18
采纳率:0%
帮助的人:9.7万
展开全部
  1. void remove_o(char *str)

  2. {

  3.      char *tmp = strchar(str, 'o');

  4.      if( tmp == null)

  5.          return;

  6.      int len_all = strlen(str);

  7.      int len_last = strlen(tmp) - 1;//o也在内,去掉

  8.      int len_head = len_all - len

  9.      char *last = malloc(len_last + 1);

  10.      char *head = malloc(len_head + 1);

  11.    

  12.      *tmp = 0;//使'o'处为结束符

  13.      tmp++;

  14.      strcpy(last, tmp);//缓存'o'后面的

  15.      *(last + len_last) = 0;

  16.       strcpy(head, str);//缓存‘o’前面的

  17.      *(head + len_head) = 0;

  18.     

  19.      //下面是交换

  20.      *str = 0;

  21.      strcpy(str, last);

  22.      strcpy(str, head);


  23.      free(tmp);

  24.      free(last);

  25.      free(head);

  26.     

  27.     remove_o(str);//回调,解决多个'o'

  28. }

本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式