Table of Contents
show
strrev()
Reverses a given string
char *strrev(char *string);
Program: Reversing a string without using string functions
#include<stdio.h>
#include<string.h>
int main()
{
char s[100];
puts("Enter string 1");
gets(s);
strrev(s);
puts("Reversed string is");
puts(s);
return 0;
}
Output
Enter string 1
bag
Reversed string is
Gab
Program: Reversing a string without using string functions
#include<stdio.h>
int main()
{
char s[100],r[100];
int i=0,j=0;
puts("Enter string");
gets(s);
while(s[i] != '\0')
{
i++;
}
while(i>0)
{
i--;
r[j] = s[i];
j++;
}
r[j] = '\0';
puts("Reversed string is ");
puts(r);
return 0;
}
Output
Enter string
bag
Reversed string is
Gab
Program: Reversing a string without using string functions
#include<stdio.h>
int main()
{
char s[100],r[100];
int i=0,j=0;
puts("Enter string");
gets(s);
while(s[i] != '\0')
{
i++;
}
while(i>0)
{
i--;
r[j] = s[i];
j++;
}
r[j] = '\0';
puts("Reversed string is ");
puts(r);
return 0;
}
Output
Enter string
bag
Reversed string is
Gab
Views: 0