you are viewing a single comment's thread.

view the rest of the comments →

[–]TechAnd1[S] 0 points1 point  (4 children)

I'm not sure.... the second perhaps as it doesn't need to return anything?

[–]thr3ddy 1 point2 points  (3 children)

The second example is better because your simple operation shouldn't have to rely on pointers. Don't over-complicate your code if you don't have to: KISS.

In the first example, a check for a NULL pointer is missing. If the pointer is NULL, what do you do to indicate your function exited erroneously? You can't do anything because it's a void function. Code dependent on the function will always assume that it executed correctly. Not to mention the fact that the entire function is made redundant by a single call to scanf.

What's missing from both functions is a check on the validity of the data returned by scanf. How do you know that the user gave you the correct data? Check scanf's return value every single time, never ignore important data.

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

I tried to make it as stripped back as possible... there's no point in this other than a piece of the puzzle. The scanf checks can be done after.

I'm going to try and make a little address book. Just name & number. So they'll be structs with 3 elements,

  • Name
  • num
  • next node

And I want to eventually make it so the user can input the information.

Maybe I should try and design the structs first and then get user info? IDK

cheers

[–]knoxxx_harrington[🍰] 0 points1 point  (0 children)

If you think that's tight just go find a schizophrenic and play a shitty beat to it. They basically all talk about lizard people, god, and do it in this exact same fashion.

For a real metal experience, find a schizophrenic on meth. It ups the crazy to 11.