Strip first and last character from C string

前端 未结 4 2087
梦毁少年i
梦毁少年i 2020-12-14 16:34

I have a C string that looks like \"Nmy stringP\", where N and P can be any character. How can I edit it into \"my string\" in C?

4条回答
  •  隐瞒了意图╮
    2020-12-14 17:05

    Further to @pmg's answer, note that you can do both operations in one statement:

    char mystr[] = "Nmy stringP";
    char *p = mystr;
    p++[strlen(p)-1] = 0;
    

    This will likely work as expected but behavior is undefined in C standard.

提交回复
热议问题