Editorial / Best Answer
Rohan
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char *str;
int i,len;
//not using any temp variable and assume we can use only string array and length
printf("Enter String : ");
scanf("%s",str);
len=strlen(str)-1;
for(i=0;i<strlen(str)/2;i++)
{
str[i]+=str[len];
str[len]=str[i]-str[len];
str[i]=str[i]-str[len--];
}
printf("Reverse String is : %s",str);
getch();
}
Write a C program to reverse the string without using strrev() function?
Profile Answers by vigneshwaran Questions by vigneshwaran
Questions by vigneshwaran
Editorial / Best Answer
RohanProfile Answers by Rohan Questions by Rohan
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char *str;
int i,len;
//not using any temp variable and assume we can use only string array and length
printf("Enter String : ");
scanf("%s",str);
len=strlen(str)-1;
for(i=0;i<strlen(str)/2;i++)
{
str[i]+=str[len];
str[len]=str[i]-str[len];
str[i]=str[i]-str[len--];
}
printf("Reverse String is : %s",str);
getch();
}