;

C program to Reverse a String without using strrev() using for loop and storing it to another variable


Tutorialsrack 03/11/2019 C

In this C program, we will learn how to write a program to reverse a string without using strrev() using for loop and storing it to another variable.

Here is the code of the program to reverse a string without using strrev() using for loop and storing it to another variable.

Code - C program to Reverse a String without using strrev() using for loop and storing it to another variable
/* C program to Reverse a String without using strrev() using for loop and storing it to another variable */
 
#include <stdio.h>
#include <string.h>
 
void main()
{
  	char Str[100], ReverseStr[100];
  	int i, j, len;
 
  	printf("Enter a String: ");
  	gets(Str);
  	
  	j = 0;
  	len = strlen(Str);
 
  	for (i = len - 1; i >= 0; i--)
  	{
  		ReverseStr[j++] = Str[i];
  	}
  	ReverseStr[i] = '\0';
 
  	printf("Reverse String is = %s", ReverseStr);
}
Output

Enter a String: tutorialsrack
Reverse String is = kcarslairotut
--------------------------------
Process exited after 8.46 seconds with return value 34
Press any key to continue . . .


Related Posts



Comments

Recent Posts
Tags