Tagged: replace string character

C program to read a string 4

C program to read a string and replaces every 5th character with “X”

The below program in C will accept a string from user. It will then process the string and replace every 5th character of the string with a character “X”. Here is the C code. #include<stdio.h> #include<conio.h> #include<string.h> void main() { char *str; int i; clrscr(); printf(“Enter a string: “); gets(str); for(i=0;i<strlen(str);i++) { if((i+1)%5 == 0) { str[i] = ‘X’; } } puts(str); getch(); } C Output Enter a string: This is a C Program ThisXis aXC PrXgram C Programming is brought you by LearnCOnline.com