Print longest common subsequence getting wrong ans

i cant find any mistake in my code
its showing wrong answer on submission but it works for many sample test cases that i tried
please help

my code:
https://ide.codingblocks.com/s/50338

question link:
https://hack.codingblocks.com/contests/c/512/277

Hi Jai,
Try running your code for the following input:
aggtab
gxtxayb
Your code gives atab
Where as the output should be gtab