S
Servé Lau
Sometimes I code like this:
char *p = strchr(buf,'\n');
if (p)
*p = 0;
But I've also seen the shorter expression:
buf[strcspn(buf, '\n')] = 0;
Are their advantages to the second one except shorter code?
char *p = strchr(buf,'\n');
if (p)
*p = 0;
But I've also seen the shorter expression:
buf[strcspn(buf, '\n')] = 0;
Are their advantages to the second one except shorter code?