exercise3

exercise3 - / for(int i=0; i<lg/2; i++) { tmp =...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream> #include <string> using namespace std; u string reverse(string str) { int lg = str.size(); int head, tail; head = 0; tail = lg-1; // string::iterator head, tail; // head = str.begin(); const char* tabstr = str.c_str(); char tmp; // char *head = &str[0]; // char *tail = &str[lg];*/ / // char *head = &(*str)[0]; // char *tail = &(*str)[lg-1]; // *tail = *head; / // *head = *tail; / cout << str[tail]; // cout << *tail;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: / for(int i=0; i&lt;lg/2; i++) { tmp = str[head]; str[head] = str[tail]; str[tail] = tmp; head++; tail--; } return str; // *head = *tail; / } int main () { string str, final_str; // the string put by the user and the reverse string s cout &lt;&lt; &quot;Enter a string : &quot;; cin.ignore(INT_MAX,'\n'); getline(cin, str); final_str = reverse(str); cout &lt;&lt; final_str &lt;&lt; endl; cin &gt;&gt; final_str; return 0; } }...
View Full Document

This note was uploaded on 11/01/2009 for the course AV 244 taught by Professor Dub during the Spring '09 term at ECE.

Page1 / 2

exercise3 - / for(int i=0; i&amp;amp;lt;lg/2; i++) { tmp =...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online