Reverse String

Write a function that takes a string as input and returns the string reversed.

Example:
Given s = "hello", return "olleh".

 

 1 char* reverseString(char* s) {
 2     int i;
 3     int j;
 4     char temp;
 5     i = 0;
 6     j = strlen(s) - 1;
 7     while(i < j){
 8         temp = s[i];
 9         s[i] = s[j];
10         s[j] = temp;
11         i++;
12         j--;
13     }
14     return s;
15 }

 

posted @ 2016-05-10 22:31  米开朗菠萝  阅读(112)  评论(0编辑  收藏  举报