I want to make a program which will first accept a string from user. Now this string will have to be replaced by another string accepted. Something like this:
Assuming user enters string: "Suvo"
and he wants it to be replaced by "k" then program should replace S with k and the result generated should be "kuvo".
similarly if user wants it to be replaced by "ka" then aprogram should replace "S" with "k" and "u"with "a" the result generated should be "kavo".
I have coded it but the output generated is not correct.
Following is the code:
#include<stdio.h>
#include<conio.h>
void str_replace(char *str,char *str1)
{
puts(str);
puts(str1);
while(*str1!='\0')
{
*str=*str1;
++str1;
++str;
}
printf("\n\n String after replacement");
puts(str);
}
void main()
{
char *str,*str1;
clrscr();
printf("\n Enter the original string");
gets(str);
printf("\n Enter the string with which you want to replace your original string \n\n");
gets(str1);
str_replace(str,str1);
getch();
}
Output
Enter the original string suvo
Enter the string with which you want to replace your original string k
String after replacement uvo
As you can see the program generates uvo instead of kuvo.
Help to fix it
Thanks


Sign In
Create Account

Back to top









