News for hackers. Stuff that matters.
Re:Helping my students overcome command-line bullshittery (2... by tedunangst on Monday November 02, 2015 @10:01PM (#10497153)
> whatever it is strcspn does.

It deletes the new line from the end of the string that fgets() insists on including, even though nobody anywhere has ever wanted it. :)

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.

http://www.cplusplus.com/reference/cstring/strcspn/

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.

Re:Helping my students overcome command-line bullshittery (2... by tptacek on Tuesday November 03, 2015 @04:00PM (#10502607)
You just chopped the last non-NUL character off that string whether it was a newline or not.
Re:Helping my students overcome command-line bullshittery (2... by marvy on Tuesday November 10, 2015 @10:26PM (#10544658)
ok, you got me there