#include #include #include void trim (char *str) { printf("STR: %s\n", str); char *a, *b; a = strchr(str, '\n'); b = strchr(str, '\r'); if (a == NULL && b == NULL) return; else *( (a-str) < (b-str) ? a : b) = '\0'; } int main(void) { char *str; str = malloc(7); str = strdup("\nhello"); trim(str); printf("-%s-\n",str); system("pause"); return EXIT_SUCCESS; }