bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

pc015.c (1022B)


      1 /*
      2  * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 30 Mar 2026
      3  * Repo: https://github.com/notamitgamer/bsc
      4  * License: MIT
      5  */
      6 
      7 /* Write a C program to reverse a string using a recursive function. */
      8 
      9 #include<stdio.h>
     10 #include<stdlib.h>
     11 #include<string.h>
     12 
     13 void reverseString(char [], char *, char *);
     14 
     15 int main() {
     16     char string[101], *p, *start, *end;
     17     printf("Enter the string (Max: 100 char): ");
     18     if(fgets(string, sizeof(string), stdin) == NULL) {
     19         printf("\nError reading input.");
     20         exit(1);
     21     }
     22     p = strchr(string, '\n');
     23     if(p) *p = '\0';
     24     printf("Before Reverse: %s", string);
     25     start = string;
     26     end = string + strlen(string) - 1;
     27     reverseString(string, start, end);
     28     printf("\nAfter reverse:  %s", string);
     29     return 0;
     30 }
     31 
     32 void reverseString(char str[], char *start, char *end) {
     33     if(start >= end) {
     34         return;
     35     }
     36     char temp;
     37     temp = *start;
     38     *start = *end;
     39     *end = temp;
     40     start++;
     41     end--;
     42     reverseString(str, start, end);
     43 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror