How to reverse a sentence with C program.

Showing Answers 1 - 25 of 25 Answers

Sandeep

  • Oct 25th, 2005
 

Take sentence in an array and get array size and then print the array in ascending order.

samrat

  • Feb 8th, 2006
 

A more undo answer can be like this

rever(char a )

{

  Was this answer useful?  Yes

Casanova

  • Mar 18th, 2006
 

I think what the question requires is that only the words in the sentence be reversed. For this follow this pseudo code:for each word in sentence: reverse (word)print reverse (sentence)for e.g. given 'an indian on road' after reversing each word we get 'na naidni no daro' on reversing this we get ' road on indian an'

  Was this answer useful?  Yes

Harshdev Joshi

  • Mar 16th, 2007
 

Program...


Code
  1. #include

  2. #include

  3. #include

  4. "Life is beautiful""Original sentence=%sn", s);

  5.     *(s + len + 1) = '';

  6.     *(s + len) = ' '' ') {

  7.             start = end + 1;

  8.             end = length;

  9. //printf("%d %dn",start,end);"After processing=%s", s);

  10.     getch();

  11. }

  12.  


This is a very simple program having following logic. Main string - Life is beautiful
After reversing words at their respective places - efiL si lufituaeb
Reversing it we get - beautiful is Life

srinivasarao

  • Oct 12th, 2007
 

A small code for this....

Code
  1. #include

  2. #include

  3. #include

  4. "this is string reverse""%c", s[i]);

  5.     getch();

  6. }

  7.  

  Was this answer useful?  Yes

kaushalgoa

  • Dec 31st, 2007
 

Code
  1. #include "stdio.h"

  2. #include "string.h"

  3. #include "stdlib.h"

  4. "Enter a Wordn");

  5.     scanf("%s""%sn""%sn"


// Note (backslash not displayed on this website.)

  Was this answer useful?  Yes

fkhanoom

  • Mar 19th, 2008
 

Code
  1. #include <stdio.h>

  2. #include <assert.h>

  3. #define MAX 100

  4. "Enter a string (MAX characters: 100): " );

  5.     //scanf( "%s", s );"%s"''

  Was this answer useful?  Yes

ananth3335

  • Mar 31st, 2008
 

I think by using this code can do the reverse opeartion

Code
  1. span style="color: #ff0000;">'n'"%c", c);

  2.     getch();

  3. }


when u enter the 'enter key' it will terminate.

  Was this answer useful?  Yes

// A valid sentence is a group of words ended with a fullstop i.e.  with a dot( . ).
int main()
{

char sentence[50];
cin>>sentence;   //Every sentence must ended with a dot.

//print the sentence
for(int i=0; i!=' . ' ;i++)
cou<<sentence[i] ;


//reverse the sentence
int length= strlen(sentence);

// suppose the length of the sentence is 10 then fullstop is in the 10th position. For reversing the sentence we have to print from 10th-1 position to the 0th position.

for(int j=length-1; j>=0; j-- )
{
cout<<sentence[j];
}

return 0;
}

  Was this answer useful?  Yes

Code
  1.  

  2. #include

  3. #include

  4. #include

  5. #define size 100

  6. "nEnter a string of msx 100 charactersn""the given string B4 reverse isn""%c""nReverse of given string isn""%c", str[i])

  7.         }

  8.  


Let us assume that the entered string is : parents are gods     
the output is as follows
 
The given string B4 reverse is :: Parents are gods
After reverse of string is          :: sdog era stnerap

  Was this answer useful?  Yes

kernel32

  • May 24th, 2008
 

Code
  1. #include<stdio.h>

  2. #include<string.h>

  3. #include<stdlib.h>

  4. "Before reversal => %sn""After first reversal => %sn""After second reversal => %sn"

  Was this answer useful?  Yes

thtsarjun

  • Sep 27th, 2009
 

I think the question is revere the order of words in the sentence. Because reversing a sentence doesn't make a sense when you can simply copy one string to other in reverse order and do.

Here is what I did and it does reverse the order of spaces used in the sentence:

Code
  1.  

  2.  

  3. #include <stdio.h>

  4. ' '' '' ' && s[i] != ''"this is very beautiful""nGiven String : %sn""Length of string: %dn""Reversed string: %sn"

  Was this answer useful?  Yes

opal_sybil

  • Aug 27th, 2010
 

Code
  1.  

  2. #include <stdlib.h>

  3. "When marimba rhythm starts to play"" ""No test to search.n"" ""Original sequence is: ""%s ""nSequence backwards is: ""%s ""n"



  Was this answer useful?  Yes

vicky_svk

  • Sep 27th, 2010
 

Code
  1.  

  2. #include<stdio.h>

  3. #include<conio.h>

  4. #include<string.h>

  5. "Enter the sentencen"' ') || (s[i] == '''';

  6.                 k++;

  7.         }

  8.         /*printf("%c",str[0][0]); */''"%c"" ");

  9.                 l--;

  10.         }

  11.         getch();

  12. }

  13.  

  Was this answer useful?  Yes

rizwann

  • Nov 29th, 2011
 

Here is the code to reverse the sentence that does not use any in built string function. if the input is:Life is good output will be good is Life ;)

Code
  1.  

  2. #include<stdio.h>

  3. /*Declaration and initialization */"Life is Good", *end, *start, *len, *space;

  4.     start = begin;

  5.     end = begin;

  6.     /*Find length of string */"%s"' ';

  7.     *(++len) = '';

  8.     len--;

  9.  

  10.     /*Reverse individual words */' ') {

  11.             space = end;

  12.             reverse(begin, end - 1);

  13.             begin = space + 1;

  14.             end = space;

  15.         }

  16.         end++;

  17.     }

  18.     *(--end) = '';

  19.     /*Reverse the entire string */"""

  20. ""%s"""

  Was this answer useful?  Yes

sachin

  • Dec 13th, 2011
 

I think you should use reverse string programme. You can store it an array and then run a loop.

  Was this answer useful?  Yes

Harish

  • Mar 21st, 2012
 

Code
  1. span style="color: #ff0000;">"Hi This is Harish""%c", *StrPtr);

  2.         }

  3. }

  4.  

  5.  

  Was this answer useful?  Yes

ARKAJIT NANDY

  • Aug 2nd, 2015
 

Code
  1. #include<stdio.h>

  2. #include<conio.h>

  3. #include<string.h>

  4. "Enter the sentence...

  5. "//searching for space or beginning//reversing and storing each word except the first word//printf("%c",st[k]);"

  6. "//for first word//printf("%c",st[k]);"Now reversing the sentence...

  7. "

  Was this answer useful?  Yes

A MANIKUMAR

  • Dec 11th, 2015
 

Example to reverse a sentence entered by user without using strings.

Code
  1. /* Example to reverse a sentence entered by user without using strings. */

  2.  

  3. #include <stdio.h>

  4. "Enter a sentence: ""%c""%c",c);

  5.     }

  6. }

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions