Reverse string without using temp
#include <stdio.h>
#include <string.h>
void reverse(char *, int start, int end);
int main(int argc, char **argv) {
if (sizeof(argv) > 1) {
printf ("Given string :%s\n", *++argv);
reverse(*argv, 0, strlen(*argv) - 1);
printf ("String after reverse : %s\n", *argv);
}
return 0;
}
void reverse(char *str, int start, int end) {
if (start < end) {
str[start] = str[start] + str[end];
str[end] = str[start] - str[end];
str[start] = str[start] - str[end];
} else return;
reverse(str, start + 1, end - 1);
}
**argv equivalent to argv[][]
*argv is equivalent to *argv[0] , content of first index.
Comments
Post a Comment