how to perform reversing a sentence Word by Word in C?

后端 未结 12 1351
伪装坚强ぢ
伪装坚强ぢ 2021-01-25 04:49
#include 

int main(void)
{
  int i,j;
  int wordstart = -1;
  int wordend = -1;
  char words[]= \"this is a test\";
  char temp;

  // Reverse each word
         


        
12条回答
  •  无人及你
    2021-01-25 05:02

    Simply we can just use a n*1 2D character array tailored to suit our needs!!!

    #include 
    
    int main()
    {
        char s[20][20];
        int i=0, length=-1;
        for(i=0;;i++)
        {
            scanf("%s",s[i]);
            length++;
            if(getchar()=='\n')
                break;
        }
        for(i=length;i>=0;i--)
            printf("%s ",s[i]);
        return 0;
    }
    

提交回复
热议问题