ILD

printf non null terminated string
作者:Yuan Jianpeng 邮箱:yuanjp89@163.com
发布时间:2025-1-14 站点:Inside Linux Development

打印一段字符,这段字符没有0结尾,但是知道长度,如何实现呢:

printf("%.8s", str)

或者

len = 8;

printf("%.*s", len, str);


前者是常量形式,后者可以是变量。


https://stackoverflow.com/questions/2239519/is-there-a-way-to-specify-how-many-characters-of-a-string-to-print-out-using-pri


Copyright © linuxdev.cc 2017-2024. Some Rights Reserved.