Re:Helping my students overcome command-line bullshittery (2...
by marvy on Tuesday November 03, 2015 @12:12AM
(#10497699)
Don't write things like that, people might believe you. That is not at all what it does.
Re:Helping my students overcome command-line bullshittery (2...
by tptacek on Tuesday November 03, 2015 @10:55AM
(#10500356)
I don't think he's being entirely serious, but you obviously can use it that way:
char foo[] = "this is a test\n";
foo[strcspn(foo, "\n")] = 0;
Re:Helping my students overcome command-line bullshittery (2...
by marvy on Tuesday November 03, 2015 @02:45PM
(#10502020)
Sure you can do that, but strcspn only found the newline, it didn't delete it. After all, you can also do
foo[strlen(foo)-1] = 0;
But I don't think anyone would say strlen modifies the string.
It deletes the new line from the end of the string that fgets() insists on including, even though nobody anywhere has ever wanted it. :)