How to replace comma (,) with semicolon (;) in a string with C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>

char *replace_comma_with_semicolon(char str[]) {
    for (int i = 0; i < strlen(str); i++) {
        if (str[i] == ',') {
            str[i] = ';';
        }
    }
    
    return str;
}

int main() {
    char str[] = "java,c,c++,c#,rust";
    
    replace_comma_with_semicolon(str);
    
    printf("%s\n", str);
    
    return 0;
}

 
 
/*
run:
 
replace_comma_with_semicolon
 
*/

 



answered Dec 3, 2024 by avibootz

Related questions

2 answers 162 views
1 answer 132 views
1 answer 124 views
1 answer 141 views
1 answer 125 views
1 answer 123 views
1 answer 2,226 views
...