I Want Programe Of Reverse A String
I Want Programe Of Reverse A String
Use standard function strrev defined in string.h
Use it likeCode:Prototype char*strrev(char*)
[/code]Code:char orignalstring[]="Happy",revstring[50]; revstring=strrev(orignalstring);
Nope, it is not a standard function.Originally Posted by vaibhav
@the OP, do a board search on 'reverse a string' - this comes up often.
Not to mention
http://cboard.cprogramming.com/annou...ouncementid=39
And not to mention how Writing In Initial Caps Really Sucks
http://www.catb.org/~esr/faqs/smart-questions.html
> I Want Programe Of Reverse A String
Did Yoda translate that into English for you?
Program reverse a string not will I give you - mmmmm
That was cruel...
It's a good thing I came accross this thread, I was wanting to learn this. Once again, you guys have been very useful and I've just found this site.
Stick around for a couple years answering these questions and find out that the advice given was not harsh. Or if you are a masochist, post a question on comp.lang.c.
Read the guidelines: show an attempt and there are those with plenty of experience that will correct all of the flaws, well beyond things you will even imagine for some time. Ignore the rules, and you will be treated like a freeloader. Quid pro quo.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
That was...interesting...?
hey try this .. im also new here but i think the porb is small so i can give u my prog toreverse a strng,,
any comments welcome.....Code:#include<stdio.h> char rev[20]; void reverse(char *x) { int i=0,j=0; while(x[i]!='\0') i++; i--; while(i>=0) { rev[j]=x[i]; j++; i--; } rev[j]='\0'; } void main() { char str[20]; printf("enter the strning to be reversed : "); scanf("%s",str); reverse(str); printf("\n\nreversed sring is : %s",rev); }
wow..
somtimes people can just amaze you.. over and over
what was that????????
you've never heard of a swap function?
in this case it would almost literally cut your time in half:and yes, I know it's C++ on a C board, but all you need to pay attention to is that for loopCode:#include <iostream> int main() { char swap; char line[]="RaceCar"; short int i=0; short int x=6; for(;i<x;i++,x--) { swap=line[i]; line[i]=line[x]; line[x]=swap; } std::cout<<line<<std::endl; return 0; }
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
> any comments welcome.....
You used void main - main always returns an int - see previous posts and the FAQ
You used a global variable
You limited the length to only 20 characters
You didn't check for input overflows
there may some error above.Originally Posted by =viki=
Code:void reverse(char *x) { int i=0,j=0,z=0; while(x[i]!='\0') i++; rev[i--]='\0'; z=i/2; //or z=i>>1; for(;z;z--) { rev[j]=x[i]; j++; i--; } }
Last edited by tqh831213; 01-03-2006 at 10:35 AM.
Here are some better swap functions...
tongue in cheek
Code:void swap(int &x, int &y) { x -= y; y += x; // y gets the original value of x x = (y - x); // x gets the original value of y } void swap2(int &x, int &y) { x ^= y ^= x ^= y; }
Originally Posted by treenef
Thanks, I needed a chuckle.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*