C program to reverse a string using pointers

Aim: Write a program to reverse a string using pointers in c

#include <stdio.h> 
#include <string.h> 
int main() 
{ 
	char str[100];
    int l, i; 
	char *begin_ptr, *end_ptr, ch; 
    printf("Enter a string: ");
    gets(str);
	l = strlen(str); 

	begin_ptr = str; 
	end_ptr = str; 

	for (i = 0; i < l - 1; i++) 
		end_ptr++;

	for (i = 0; i < l / 2; i++) { 
		ch = *end_ptr; 
		*end_ptr = *begin_ptr; 
		*begin_ptr = ch; 

		begin_ptr++; 
		end_ptr--; 
	} 
    
	printf("Reverse of the string: %s\n", str); 

	return 0; 
} 
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments