View Single Post
Old 10-27-2005, 07:27 PM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
one thing comes to mind
Code:
 //C++
#include <iostream>
#include <string>
void reverse(std::string &str)
{
    char tmp;
    for(int i=str.size()-1, j=0; i > j; i--, ++j)
    {
        tmp=str[i];
        str[i]=str[j];
        str[j]=tmp; 
    }
}

int main(){
  std::string foo("string");
  std::cout << foo << std::endl;
  reverse(foo);
  std::cout << foo << std::endl;
  return 0;
}
Code:
/* C */
#include <stdio.h>
#include <string.h>

void reverse(char str[])
{
    char tmp;
    int i = strlen(str)-1, j=0;
    for(; i > j; i--, ++j)
    {
        tmp=str[i];
        str[i]=str[j];
        str[j]=tmp; 
    }
}

int main(){
  char foo[] = "string";
  printf("%s\n", foo);
  reverse(foo);
  printf("%s\n", foo);
  return 0;
}
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote