字符串倒置但不改变单词顺序

在这里插入代码片
#include<stdio.h>
#include<string.h>
void squrt(char c[],int m,int n)
{
    int i,j=n-m;
    char t;
    for(i=0;i<(n-m)/2;i++)
    {
        t=c[i];
        c[i]=c[j-1-i];
        c[j-1-i]=t;
    }
}
int main()
{
    int i,j,from,to;
    char c[81];
    gets(c);
    j=strlen(c);
    squrt(c,0,j);
 puts(c);
    i=0;
    while(c[i]!='\0'&&c[i]!=' ')
    {
        from=i;
        i++;
        while(c[i]!=' '&&c[i]!='\0')
        {
   i++;
  }
        to=i;
  squrt(c,from,to);
  printf("from:%d   to:%d\n",from,to);
    }
 puts(c);
 return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_45906993/article/details/103657120