sam sam - 1 month ago 8
C Question

How to remove commas from a string in C

Say I have a string of "10, 5, 3" How can I get rid of the commas so the string is just "10 5 3"? Should I be using strtok?

Answer
char *r, *w;
for (w = r = str; *r; r++) {
    if (*r != ',') {
        *w++ = *r;
    }
}
*w = '\0';
Comments