mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
New file fo Reverse String Using Stack in C
This commit is contained in:
parent
cdc026c81b
commit
3096bb4a72
@ -5,15 +5,19 @@ int main()
|
||||
char str[100]; //initialize the string
|
||||
int top = -1; //give top=-1 so that when first element is scanned index will be 0
|
||||
int i = 0;
|
||||
|
||||
printf("Enter string :- ");
|
||||
fgets(str,100,stdin); //input of string from the user
|
||||
fgets(str,100,stdin); //input of string from the user
|
||||
|
||||
while(str[i]!='\0')
|
||||
{
|
||||
top++;
|
||||
stack[top] = str[i]; //store each index char of str in stack
|
||||
i++;
|
||||
}
|
||||
|
||||
i = top; //give i=top so that we can print the string in reverse
|
||||
|
||||
printf("\nReverse of the string is :- \n");
|
||||
while (i != -1)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user