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.
http://www.cplusplus.com/reference/cstring/strcspn/