bsc

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

root / semester_1 / tuition-c / P065.c

P065.c (588B)


      1 /* Write a program to reverse a string */
      2 
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 #include <string.h>
      6 
      7 void str_rev(char[]);
      8 
      9 int main()
     10 {
     11     char str[101];
     12     printf("Enter the string (Max: 100 Character): ");
     13     gets(str);
     14     printf("\nBefore Reverse: %s", str);
     15     str_rev(str);
     16     printf("\nAfter Reverse: %s", str);
     17     return 0;
     18 }
     19 
     20 void str_rev(char str[])
     21 {
     22     int i, j;
     23     char temp;
     24     i = 0;
     25     j = strlen(str) - 1; // not taking the null
     26     while (i < j)
     27     {
     28         temp = str[i];
     29         str[i] = str[j];
     30         str[j] = temp;
     31         i++;
     32         j--;
     33     }
     34 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror