C Programming code for Reversing the given String – KLETech

Write a Modular C Programming Code for Reversing the given String | Sentence?

CODE:

#include<stdio.h>
#include<string.h>
void reverse_string(char string[]);
main()
{
char string[100];
printf("Enter the string: ");
gets(string);
reverse_string(string);
printf("\nThe reversed string is :");
puts(string);
}
void reverse_string(char string[])
{
char temp;
int n = strlen(string);
int low_limit = 0;
int high_limit = n-1;
while(low_limit<high_limit)
{
temp = string[low_limit];
string[low_limit]=string[high_limit];
string[high_limit] = temp;
high_limit --;
low_limit ++;
}
}

 

OUTPUT

Enter the string: Experience is the name everyone gives to their mistakes

The reversed string is :sekatsim rieht ot sevig enoyreve eman eht si ecneirepxE

Process returned 0 (0x0) execution time : 3.398 s
Press any key to continue.

 

Please find some more codes of 1D Arrays, 2D Arrays, Pointers on the below page:

Top 100+ C Programming codes – KLE Technological University

 

Leave a Comment