Learn program of how to reverse a string in C.
I’m learning the C language and I have an issue in string topic. The issue is that I’m not able to make a program to reverse a string. Can you help me with this?
I’m learning the C language and I have an issue in string topic. The issue is that I’m not able to make a program to reverse a string. Can you help me with this?
Given below is the program to reverse a string (using strrev) in c:
#include<stdio.h>
#include<string.h>
int main()
{
char a[50];
printf(“Enter a string you want to reverse: \n”);
gets(s);
strrev(s);
printf(“Reverse of the given string is: \n”);
return 0;
}
Given below is the program to reverse a string (without strrev) in c:
#include<stdio.h>
int main()
{
char a[50], b[50];
int begin, end, count=0;
printf(“Enter a string you want to reverse: \n”);
gets(s);
while(a[count]!=’\0’)
count++;
end=count-1;
for(begin=0; begin<count;begin++)
{
b[begin]=a[end];
end–;
}
b[begin]=’\0’;
printf(“%s\n”, a);
return 0;
}