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

后端 未结 12 1455
伪装坚强ぢ
伪装坚强ぢ 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:10

    #include
    #include
    #include
    int main()
    {
    char st[50], rst[50];
    printf("Enter the sentence...\n");
    gets(st);
    int len=strlen(st), p;
    int j=-1,k;
    p=len;
    for(int i=(len-1); i>=0; i--)
    {
        //searching for space or beginning
        if(st[i]==' ')
        {
            //reversing and storing each word except the first word
            for(k=i+1;k

提交回复
热议问题