简体   繁体   中英

c: remove two characters from string

I'm working on the string: {()} my code searches for the first ) and replaces it and the character before it ( with whitespace and the result is { }

What i want to do instead of replacing the match to whitespaces is to remove the parentheses from the string and recursively check the string again using my existing code. I'm trying to find a way to collapse the remaining characters using memmove or something similar

char openKey[] = "({<[";
char closeKey[] = ")}>]";
pch = strpbrk(parenthesesStack, closeKey);
while (pch != NULL)
{

    if (opposits(*(pch-1),*pch)){
        printf("%c %c\n" , *(pch-1), *pch);
        memmove(pch-1,"  ",2);
    }
    pch = strpbrk (parenthesesStack,closeKey);
}

So you want to move the rest of the string 2 positions to the left?

Try this:

    memmove(pch-1, pch+1, strlen(pch+1) + 1);

与其使用memmove()strlen()strcpy()使用strcpy()

strcpy( pch - 1, pch + 1);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM