Skip to main content
15 events
when toggle format what by license comment
Jan 5, 2022 at 14:09 comment added user245050 Toby, Is there any value in returning the pointer that was passed?: There are already few standard C library functions that return the pointer - like, strcat(), strcpy(), etc.
Jan 5, 2022 at 14:06 comment added user245050 Toby, Good handling of malloc: I actually handle that situation first where code is less before returning so that it is more clear / more readable to the user. So, sometimes I use if (!substring) first and sometimes I use if (substring) first.
Jan 5, 2022 at 14:03 comment added user245050 Toby, Is there a good reason not to use the standard library rand() for this function?: The man pages say that random() is better. See the paragraph below NOTES section in this link: linux.die.net/man/3/rand.
Jan 5, 2022 at 14:02 comment added user245050 Toby, long vs size_t: long is my personal preference. long guards against negative numbers being passed by user by mistake and long is also very large to satisfy almost all user needs. I haven't seen any use case of an integer greater than LONG_MAX (9,223,372,036,854,775,807) when dealing with strings. Also, if the standard C library uses size_t, it doesn't mean that I should also use size_t.
Jan 5, 2022 at 13:58 comment added user245050 Toby, scanf("%*[^\n]"),scanf("%*c"): Will this work correctly if EOF is encountered without newline being encountered?
Jan 5, 2022 at 13:55 comment added user245050 Toby, I have made following changes in my code according to your review: (1) I changed c from char to int. (2) I have done the simplification - I have now used return ((!str) || (!(*str)));. (3) I have changed my code and now I am using isspace(). (4) I have put in documentation that the target is ASCII. (5) I am planning to use C string library functions from now on (like memcpy(), strncpy(), etc.).
S Nov 30, 2021 at 19:58 history mod moved comments to chat
S Nov 30, 2021 at 19:58 comment added Mast Comments are not for extended discussion; this conversation has been moved to chat.
Nov 30, 2021 at 9:16 history edited Toby Speight CC BY-SA 4.0
Oops - meant "else" not "and". Thanks @chux
Nov 30, 2021 at 8:55 history edited Toby Speight CC BY-SA 4.0
added 10 characters in body
Nov 30, 2021 at 8:47 history edited Toby Speight CC BY-SA 4.0
Improvements suggested by Chux
Nov 26, 2021 at 7:50 history edited Toby Speight CC BY-SA 4.0
Word choice - thanks @Amit
Nov 25, 2021 at 16:12 history edited Toby Speight CC BY-SA 4.0
Bug fix
Nov 25, 2021 at 14:51 history edited Toby Speight CC BY-SA 4.0
Elaborate on the final sentence
Nov 25, 2021 at 10:25 history answered Toby Speight CC BY-SA 4.0