diff --git a/data_structures/stack/Reverse_String_Using_Stack.c b/data_structures/stack/Reverse_String_Using_Stack.c index f5730435..d4225578 100644 --- a/data_structures/stack/Reverse_String_Using_Stack.c +++ b/data_structures/stack/Reverse_String_Using_Stack.c @@ -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) {