Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

C Program to reverse a string without using strrev()

Hello readers, in this post i am going to write a C Program which has been asked in Interview from long time.

The question is  “Write a program to Reverse a String without using strrev() in C”.

Well, I going to write a very simple C program to reverse a string for the above question.

C Program to reverse a string:

#include 
#include 
int main()
{
	char mystring[50];
	int len, i;
		
	//print a string about the program
	printf("C Program to reverse a string\n");
    printf("Enter a string: ");
   	
	//get the input string from the user
	scanf("%s", mystring);
	
	//find the length of the string using strlen()
	len = strlen(mystring);
	
	//loop through the string and print it backwards
	for(i=len-1; i>=0; i--){
		printf("%c", mystring[i]);	
	}
    return 0;
}

Output of the above program will be:

C Program to reverse a string
Enter a string: agurchand
dnahcruga
--------------------------------
Process exited after 1.687 seconds with return value 0
Press any key to continue . . .

It’s a pretty easy program, so just read the comments in the above C program to understand what each line of the code is doing.

Enjoy the day!

The post C Program to reverse a string without using strrev() appeared first on TutorialsMade.



This post first appeared on TutorialsMade - Ultimate Tutorial, please read the originial post: here

Share the post

C Program to reverse a string without using strrev()

×

Subscribe to Tutorialsmade - Ultimate Tutorial

Get updates delivered right to your inbox!

Thank you for your subscription

×