> int n;
> char *str, *str1;
> scanf("%s", str);
> scanf("%s", str1);
> scanf("%d",&n);
int n
places spce for an int on the stack, and you tell scanf
to place the int in it. Fine.
char *str
places spaces for a pointer to character on the stack.
However, you don't tell scanf to place its data in it
(you lack the &), but where it's pointing to. And you
haven't made it point anywhere, so it's pointing ...
somewhere unknown.
- char *str,*str1;
+ char str[256],str1[256];
or
- char *str,*str1;
+ char *str=malloc(256),*str1=malloc(256);
However, remember than with scanf, you can't (AFAIK) size
the allocated memory to what is read, thus, stack smashing
possibility in the first patch, and arena corruption in
the second. A safer way is to read little bits by little
bits (of known size) and allocate accordingly.
--
Vincent Penquerc'h