TagTrimming

How to left-trim a C string

Reading a file or any output stream usually comes back with leading to trailing whitespace. The following code snippet removes any whitespace on the left of a c string. char * str_ltrim(char * _arg) { if (_arg == NULL)return NULL; int i = 0, size = 0, j = 0; char * result; size = strlens(_arg)+1; while (isspace(*(_arg + (i++)))); if ((result = (char *)malloc((1 + (size - (i--)))*sizeof(char))) ==...

Categories

Tags

Subscribe to our Newsletter