17
Feb
String Reversal
Related Blog Items
- Palindrome Checker
- String to Integer (atoi)
- const correctness
- String Pattern Matching: Write a function that checks for a given pattern at the end of a given string
- Convert integer to binary string
/*!
* string_reverse.c: Reverse a string Feb 17, 2006
*/
#include <stdio.h>
#include <string.h>
void reverse_str(char *str, int start, int end)
{
char c = str[start];
str[start] = str[end];
str[end] = c;
start++;
end–;
if (start < end)
reverse_str(str, start, end);
}
int main ()
{
char str[] = "vijoeyz";
int len = strlen(str);
reverse_str(str, 0, len-1);
puts(str);
return 0;
}
Popularity: 24%
You need to log on to convert this article into PDF
Related Blog Items - Palindrome Checker
- String to Integer (atoi)
- const correctness
- String Pattern Matching: Write a function that checks for a given pattern at the end of a given string
- Convert integer to binary string
Related Blog Items
- Palindrome Checker
- String to Integer (atoi)
- const correctness
- String Pattern Matching: Write a function that checks for a given pattern at the end of a given string
- Convert integer to binary string
Here is one more algo for string reversal using recursive function… this program is slightly different than Vijoeyz’s version but similar and does the same thing….
int string_reverse(const char * src, char *dst)
{
int len;
if (*src == ”)
{
return 0;
}
len = string_reverse(src + 1, dst);
*(dst + len) = *src;
return len + 1;
}
February 20th, 2007 at 11:51 am
I’ve written the above program (which is in comment section) as a part of palindrome checker for one of my client in a freelancing site..
February 20th, 2007 at 11:53 am