Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

replacing a character in string in C

#include<stdio.h>
#include<conio.h>
main()
{
int i;
char a,b,str[100];
printf("Enter the string");
gets(str);
//asking for replacement
printf("enter the character to be replaced");
scanf("%c",&a);
// which letter to replace the existing one
printf("enter the character to replace");
scanf("%c",&b);
for(i=0;str[i]!='';i++)
{
    if(str[i]==a)
    {
    str[i] = b;
    }
    else
    continue;
}
printf("the new string is");
puts(str);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #replacing #character #string #C
ADD COMMENT
Topic
Name
9+7 =