P065.c (724B)
1 /* 2 * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 12 Jan 2026 3 * Repo: https://github.com/notamitgamer/bsc 4 * License: MIT 5 */ 6 7 /* Write a program to reverse a string */ 8 9 #include <stdio.h> 10 #include <stdlib.h> 11 #include <string.h> 12 13 void str_rev(char[]); 14 15 int main() 16 { 17 char str[101]; 18 printf("Enter the string (Max: 100 Character): "); 19 gets(str); 20 printf("\nBefore Reverse: %s", str); 21 str_rev(str); 22 printf("\nAfter Reverse: %s", str); 23 return 0; 24 } 25 26 void str_rev(char str[]) 27 { 28 int i, j; 29 char temp; 30 i = 0; 31 j = strlen(str) - 1; // not taking the null 32 while (i < j) 33 { 34 temp = str[i]; 35 str[i] = str[j]; 36 str[j] = temp; 37 i++; 38 j--; 39 } 40 }