Home > Article > Backend Development > Write a C program to reverse a string without using library functions
strrev (string)
Before flipping a string without using a function, let us first see how to flip a string using the string function strrev() so that we can Easily spot the differences and get a clear understanding of the concepts −
#include<stdio.h> main (){ char a[50] ; clrscr(); printf (“enter a string”); gets (a); strrev (a); printf(“reversed string = %s”,a) getch (); }
enter a string Hello reversed string = olleH
Now Let’s look at a program to reverse a string without using strrev() function −
#include <stdio.h> #include <conio.h> #include <string.h> void main(){ char string[20],temp; int i,length; printf("Enter String : "); scanf("%s",string); length=strlen(string)-1; for(i=0;i<strlen(string)/2;i++){ temp=string[i]; string[i]=string[length]; string[length--]=temp; } printf("</p><p>Reverse string :%s",string); getch(); }
Enter String : Tutorialspoint Reverse string :tniopslairotuT
The above is the detailed content of Write a C program to reverse a string without using library functions. For more information, please follow other related articles on the PHP Chinese website!