How to replace whitespaces and tabs with nothing in C

1 Answer

0 votes
#include <stdio.h>

void remove_whitespaces_and_tabs(char str[]) {
    char *write = str, *read = str;
    
    do {
       if (*read != ' ' && *read != '\t') {
           *(write++) = *read;
       }
    } while (*(read++));

}

int main() {
    char str[] = "   C      Progr\tammig     \t";
    
    remove_whitespaces_and_tabs(str);
    
    printf("%s\n", str);

    return 0;
}



/*
run:

CProgrammig

*/

 



answered May 31, 2024 by avibootz
...