Char str[]="DOLLAR";Here , you have the base address of array i.e. str.By using only one pointer variable, you have to replace the occurrence of 'L' with '$$'. (after replacement, it should be DO$$$$AR)can any body suggest efficient method?

Showing Answers 1 - 2 of 2 Answers

R.S.JAYASATHYANARAYANAN

  • Dec 27th, 2006
 

char str[]="DOLLAR"

char *ptr;

*(ptr+2)='$$';

*(ptr+3)='$$';

then it will   display DO$$$$AR

  Was this answer useful?  Yes

mekala

  • Jan 9th, 2007
 

    #include<stdio.h>
#include<string.h>
void replace(void)
{
char *ptr="$$";
printf("%s",ptr);
}
int main()
{
char s[]="DOLLAR";
int i;
        for(i=0;i<=strlen(s);i++)
        {
                if (s[i]!='L')
                {
                printf("%c",s[i]);
                }
                else
                {
                replace();
                }
        }
}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.