The simplest way of printing a portion of a char[] in C

后端 未结 5 748
被撕碎了的回忆
被撕碎了的回忆 2020-12-13 13:39

Let\'s say I have a char* str = \"0123456789\" and I want to cut the first and the last three letters and print just the middle, what is the simplest, and safes

5条回答
  •  隐瞒了意图╮
    2020-12-13 14:08

    I believe there is some magic you can do with printf that will only print a certain number of characters, but it's not commonly understood or used. We tried to do it at a previous job and couldn't get it to work consistently.

    What I would do is save off a character, null that character in the string, print it, then save it back.

提交回复
热议问题