Skip to content
Advertisement

replacing “”” by empty character

I need to replace ” (ASCII value 34) char by empty character “”.

In output, instead of quote i get an “?” question mark character. I tried to use things like:

mystring[itit] = "";

mystring[itit] = '';

mystring[itit] = "O";

My code:

strcpy( mystring ,op->data.value.str  );
          for(itit=0;itit<10;itit++)
          {
            if(mystring[itit] == 34)
            {
              mystring[itit] = NULL;
            }


          }
          printf( "%sn",mystring);

Any ideas how to fix that?

For clarification: the strings in mystring are like:

“hello”

“place “

“school”

all with the quotation marks – I Actually need to remove them and get:

hello

place

school

Advertisement

Answer

What you need to do is remove the character, not replace it, since you’re not replacing it with anything. To do this, when you find the character is question, you need to move the remaining characters down.

int i,j;

strcpy(mystring, "aa"bb"cc");
for(i=0,j=0;i<10;i++)
{
    if(mystring[i] != '"')
    {
        mystring[j] = mystring[i];
        j++;
    }
}
mystring[j] = '';
printf("mystring=%sn",mystring);

Result:

mystring=aabbcc
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement