Getting runtime error in compiler and parser problem(COMPILER)

I am getting runtime error(SIGSEGV) but when I run it on geeksforgeeks ide then program run without any error Here is the GFG code link “Online Compiler and IDE - GeeksforGeeks” . Ideone.com also gives runtime error “v7nLuW - Online C Compiler & Debugging Tool - Ideone.com”. Please correct me, where I am commiting mistake.

You are getting SIGSEV because of declaring char *str. You may refer What's difference between char s[] and char *s in C? - GeeksforGeeks

You can simply declare char str[size].

We don’t know size of string untill the input given, so I tried to use char * str. As it points to the string without worrying about size of string.
Secondly, char *str should gives error when we try to modify the string becoz the string is stored in read-only area.
Please correct me if I wrong

You are right, it is stored in read only memory. I think you need to dynamically allocate memory. Take size as maximum possible+1 (for null character)

You should see this.

1 Like

@sebastian very very thanks!