4 ms·
> 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 wante
by tedunangst 11y ago
> 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. :)
- marvy 11y agoDon't write things like that, people might believe you. That is not at all what it does. http://www.cplusplus.com/reference/cstring/strcspn/ http://www.cplusplus.com/reference/cstring/strcspn/
- tptacek 11y agoI 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;
- marvy 11y agoSure 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.