[Solved] return statement in a for loop [closed]


What if string is 0 length or count is 0? In your second case, you don’t return a value.

This should be giving a compiler warning and will probably cause a crash as it returns whatever it wants.


Edit

Ok, the problem is deeper – you are never getting to the part of the code that sets the ‘\0’ in the for loop with those initial conditions (“zoom” and 3). Therefore, your string could also not have that terminator set depending on how nice malloc is feeling. You need to set the NUL value if there is a string even if you exit the for loop. This is why the second was failing and not the first – it was indeed missing the return statement.

5

solved return statement in a for loop [closed]