problem 38


#include <stdio.h>

int main() {
    char str[100];   
    char searchChar; 
    char replaceChar; 

    
    printf("Enter a string: ");
    fgets(str, sizeof(str), stdin);

    
    printf("Enter the character to find: ");
    scanf(" %c", &searchChar);  

    
    printf("Enter the character to replace with: ");
    scanf(" %c", &replaceChar);  

    
    for (int i = 0; str[i] != '\0'; i++) {
        if (str[i] == searchChar) {
            str[i] = replaceChar;
        }
    }

    
    printf("Modified string: %s", str);

    return 0;
}




Contact Form