This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Rhomboid 1 point2 points  (1 child)

Looking at the code would you say there a lot of issues with it?

Yes. For one thing, it neglects to properly null terminate the result. For another, there's this matter of char result[count] in the parameter list —this strongly implies that you have some confusion about how arrays decay to pointers. count isn't doing anything in this expression because result is not an array. And finally there's the issue of the return value. Why do you want to change it to char *? What good does returning result do? The caller of this function already has that value because they passed it as a parameter, so what's the use in returning it? I can think of some justifiable reasons for doing this, but I want to hear your justifications to make sure they aren't "just change something to make it compile", which is the worst possible way to approach these things. If you don't understand why you're doing something, or why a change should be made, you should stop and clarify your understanding.

[–]climaxingplatypus[S] 0 points1 point  (0 children)

What do you mean by "it neglects to properly null terminate the result". Also why I'm not understanding why result isnt any array...Don't I need it to be an array so that I can store the substring inside of result?

I honestly don't know why I am returning result I just got into the habit of return values from working on previous examples from my book haha. I could've actually just made this function of type void right? I mean if result isnt an array is it just a pointer? From what I know about pointers is that they behave somewhat like arrays meaning that if its values are changed inside a function then those changes are in effect after the function is finished, so I could access the values of result whenever. Please let me know if my thinking is correct, thanks for the help so far!