-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathreverse.c
More file actions
53 lines (47 loc) · 717 Bytes
/
reverse.c
File metadata and controls
53 lines (47 loc) · 717 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
#include <string.h>
#define MAX 10
char stack[MAX];
int top = -1;
void push(char);
char pop(void);
int main()
{
char str[MAX];
int len, i;
printf("Enter a String: ");
scanf("%s", str);
len = strlen(str);
for (i = 0; i < len; i++)
{
push(str[i]);
}
for (i = 0; i <= len; i++)
{
str[i] = pop();
}
printf("Reversed String is: %s", str);
return 0;
}
void push(char c)
{
top++;
stack[top] = c;
}
char pop(void)
{
char c;
if (top == -1)
{
return '\0';
}
else
{
c = stack[top];
top--;
return c;
}
}
// OUTPUT
// Enter a String: mango
// Reversed String is: ognam