how to remove \n from a string c

C
str[strcspn(str, "\n")] = 0;
Source

Also in C: