How to print only certain parts of a string?

后端 未结 2 1224
终归单人心
终归单人心 2021-01-12 08:34

I have a string const char[15] and I want to print it like this:

Label-one: characters [0,13)
Label-two: characters [

2条回答
  •  清酒与你
    2021-01-12 09:29

    printf( "%.13s", labelOne );   // stops after thirteen characters.
    printf( "%.3s", &labelOne[ 13 ] );  // prints three characters of the string that starts at offset 13
    

    I'm noticing a possible fencepost error/inconsistency in your question or my answer, depending on your point of view. The correct answer for the second example may be:

    printf( "%.3s", &labelOne[ 12 ] ); 
    

提交回复
热议问题