Differences

This shows you the differences between two versions of the page.

Link to this comparison view

strrev [2014/10/26 01:52] (current)
Line 1: Line 1:
 +===== String reverse =====
  
 +<code c++>
 +#include <​iostream>​
 +#include <​string>​
 +
 +using namespace std;
 +
 +int main(int argc, char **argv, char **envp);
 +void strrev(char *s);
 +
 +int main(int argc, char **argv, char **envp)
 +{
 +    char *name = "madan nain";
 +    cout << "orig = " << name << endl;
 +    strrev(name);​
 +    cout << "​rev ​ = " << name << endl;
 +    return 0;
 +}
 +
 +void strrev(char *s)
 +{
 +    int slen = strlen(s);
 +    int i = 0;
 +    char *st = s;
 +    char *t = s + slen -1;
 +    char temp;
 +
 +    if (slen > 1)
 +    {
 +        cout << *st << " : " << *t << endl;
 +        while (i < slen / 2)
 +        {
 +            temp = *st;
 +            *st = *t;
 +            *t = temp;
 +            s++;
 +            t--;
 +            i++;
 +        }
 +    }
 +}
 +</​code>​
 +
 +  * [[cplusplus|Back to C++]]
strrev.txt ยท Last modified: 2014/10/26 01:52 (external edit)
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0