forked from suman-shah/c-program-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecursive.c
More file actions
31 lines (25 loc) · 667 Bytes
/
Copy pathrecursive.c
File metadata and controls
31 lines (25 loc) · 667 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include <string.h>
void reverse_string(char*, int, int);
int main()
{
//This array would hold the string upto 150 char
char string_array[150];
printf("Enter any string:");
scanf("%s", &string_array);
//Calling our user defined function
reverse_string(string_array, 0, strlen(string_array)-1);
printf("\nReversed String is: %s",string_array);
return 0;
}
void reverse_string(char *x, int start, int end)
{
char ch;
if (start >= end)
return;
ch = *(x+start);
*(x+start) = *(x+end);
*(x+end) = ch;
//Function calling itself: Recursion
reverse_string(x, ++start, --end);
}