Tuesday, February 26, 2013

C Language Example # 26 Example : Find and Replace Character

C Language Example # 26 Example : Find and Replace Character.

* Find character and replace.

//Written by Latest Technology Guide    
//Title : C Language Example # 26 Example : Find and Replace Character.

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
void main()
{
clrscr();
int i,n,j=0;
char str[70],addstr[50],find[2],replace[2];

printf("Enter the String :");
gets(str);

printf("Enter Character to Find : ");
scanf("%c",&find);

printf("Enter Character to Replace : ");
scanf("%c",&replace);

for(i=0;i<strlen(str);i++)
{
if(str[i]==find[0])
str[i]=replace[0];
}

puts(str);

getch();
}


Output:

* Enter String.

* Enter character to find
* Enter character to replace.

--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 26 Example : Find and Replace Character.
* Program will find character and replace with new character.

Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements. 

No comments:

Post a Comment