Specifying the maximum string length to scanf dynamically in C (like “%*s” in printf)

后端 未结 3 338
小蘑菇
小蘑菇 2020-12-06 04:51

I can specify the maximum amount of characters for scanf to read to a buffer using this technique:

char buffer[64];

/* Read one li         


        
3条回答
  •  失恋的感觉
    2020-12-06 05:20

    Another option is to #define the length of the string:

    #define STRING_MAX_LENGTH "%10s"
    

    or

    #define DOUBLE_LENGTH "%5f"
    

提交回复
热议问题