sizeof(str) does not do what you expect. Given a char *str , sizeof(str) will not give you the length of that string.
stackoverflow.com