Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 How to reverse a phrase!? Help!, use reverse iterator?

views
     
TSukiya
post Mar 2 2006, 01:34 PM, updated 20y ago

* Hardcore Adventurer *
******
Senior Member
1,079 posts

Joined: Sep 2005
From: Planet Earth

Need help !!! In C program, how to reverse a sentence like "Games" become "semaG"?
How? can anyone teach me ? if can, give me the source code as well ! thanks!

not realli need to use reverse iterator, u can tell us how to use other function oso ! thanks
nxfx
post Mar 2 2006, 02:10 PM

Enthusiast
*****
Senior Member
979 posts

Joined: Jan 2003


put the string into array and print it out backward.
TSukiya
post Mar 2 2006, 02:23 PM

* Hardcore Adventurer *
******
Senior Member
1,079 posts

Joined: Sep 2005
From: Planet Earth

can u provide de source code as well? thanks
earl-ku
post Mar 2 2006, 02:23 PM

Chlorophiliac
*******
Senior Member
4,587 posts

Joined: Jan 2003
From: Golden Meadow
declare 2 similiar long string to hold the word, use the last in first out method to place the particular word into the 2nd string, then print them on screen
TSukiya
post Mar 2 2006, 02:35 PM

* Hardcore Adventurer *
******
Senior Member
1,079 posts

Joined: Sep 2005
From: Planet Earth

thanks for your idea... i m juz not very gud in source code... there's way i need help here ! can provide?

nxfx
post Mar 2 2006, 02:49 PM

Enthusiast
*****
Senior Member
979 posts

Joined: Jan 2003


It's been quite sometime since I've done C, well here goes....

char str[10];

str = "Games";

for(i=len(str) ;i >=0 ; i--) {
printf("%c",str[i]);
}
dstl1128
post Mar 2 2006, 02:52 PM

Look at all my stars!!
*******
Senior Member
4,464 posts

Joined: Jan 2003
Use strrev().
TSukiya
post Mar 2 2006, 02:59 PM

* Hardcore Adventurer *
******
Senior Member
1,079 posts

Joined: Sep 2005
From: Planet Earth

thanks ! any other idea or source code can provide to do this question ?
nxfx
post Mar 2 2006, 03:00 PM

Enthusiast
*****
Senior Member
979 posts

Joined: Jan 2003


strrev() is not part of ANSI C, he may not able to use it.
silverhawk
post Mar 2 2006, 03:11 PM

Eyes on Target
Group Icon
Elite
4,956 posts

Joined: Jan 2003


Code it out yourself. Don't be a friggin lazy arse hoping for someone to provide you a full answer immediately. People have already told you how you can do it, just implement it yourself. If you are unable to do such a simple task, i wonder why you're even learning how to program in the first place...

nxfx, you should not have posted the source code for him. We should not be encouraging this sort of behavior among programmers... let him show some effort and then guide him. If he does not show any effort himself, we should not waste any effort on him either.
naim_mahmood
post Mar 2 2006, 03:20 PM

Getting Started
**
Junior Member
105 posts

Joined: Jul 2005


I hope i'm not too late smile.gif

this is actually the concept of whistling.gif
omg i forgot the name doh.gif

CODE
#include "stdio.h"

void reverse()
{
   char ch;
   scanf("%c",&ch);
     
   if(ch != 'p')
   reverse();
   
   printf("%c",ch);    
   
   }

int main()
{
   reverse();
   
   getch();
   
   }

naim_mahmood
post Mar 2 2006, 03:22 PM

Getting Started
**
Junior Member
105 posts

Joined: Jul 2005


oops...

sorry.... i din know cannot post answer shocking.gif
TSukiya
post Mar 2 2006, 03:36 PM

* Hardcore Adventurer *
******
Senior Member
1,079 posts

Joined: Sep 2005
From: Planet Earth

QUOTE(silverhawk @ Mar 2 2006, 03:11 PM)
Code it out yourself. Don't be a friggin lazy arse hoping for someone to provide you a full answer immediately. People have already told you how you can do it, just implement it yourself. If you are unable to do such a simple task, i wonder why you're even learning how to program in the first place...
*
I oledi told u, if i know how to program in the first place! I wont ask u !!!
I here juz wanna get some idea of the code ...

fly
post Mar 2 2006, 04:18 PM

¯\(°_o)/¯
Group Icon
VIP
1,119 posts

Joined: Jan 2003
QUOTE(ukiya @ Mar 2 2006, 03:36 PM)
I oledi told u, if i know how to program in the first place! I wont ask u !!!
I here juz wanna get some idea of the code ...
*
If you don't know how to program, then what is the source code going to be used for?
silverhawk
post Mar 2 2006, 07:40 PM

Eyes on Target
Group Icon
Elite
4,956 posts

Joined: Jan 2003


QUOTE(ukiya @ Mar 2 2006, 03:36 PM)
I oledi told u, if i know how to program in the first place! I wont ask u !!!
I here juz wanna get some idea of the code ...
*
Get some idea? Reversing the string is incredibly easy... but if you didn't know how to do it and wanted some guidance that isn't so bad. However your question was answered in the 2nd post, but you wanted the source code. Then example codes were given later by other people and you still wanted the source code.

Its pretty obvious all you want is a direct working solution so you can copy and paste. If you still say you don't know how to do it, you got bigger issues to tackle than reversing a string. Go read up on arrays and loops.

 

Change to:
| Lo-Fi Version
0.0148sec    0.42    5 queries    GZIP Disabled
Time is now: 24th December 2025 - 01:17 AM