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.

void main()
	char *str;
	int i;
	printf("Enter a string: ");
		if((i+1)%5 == 0)
			str[i] = 'X';

C Output

Enter a string: This is a C Program
ThisXis aXC PrXgram

C Programming is brought you by LearnCOnline.com

You may also like...

4 Responses


    calculate the total price for items :
    – price RM2 and RM5
    – price >RM5

    So , how to solve this problem using file operation and control statements ?

  2. Sateesha says:

    Function shall sum members of given one-dimensional array. However, it should sum only members whose number of ones in the binary representation is higher than defined threshold (e.g. if the threshold is 4, number 255 will be counted and 15 will not)
    – The array length is arbitrary
    – output the results to the stdout

  1. May 4, 2015

    […] Read a string and replaces every 5th character with

Leave a Reply

Your email address will not be published.

FREE C Programming Cheatsheet

FREE C Programming Cheatsheet


Cheatsheet for a quick glance at C programming concepts and syntax

Thank you! Check you inbox and access your cheat-sheet