简体   繁体   English

Printf(%s)打印0

[英]Printf(%s) prints 0

I have this command in my project (in C): 我的项目中有此命令(在C中):

int addFinalDataStr(char* value) 
{
    fprintf(objFile,"%-7.7s\n",value);
    fflush(objFile);
}

When I call this method with the value like: "60100" , it prints "60100" with no problems, but when i call it with a string like "37777777773" it just prints out "0" . 当我使用诸如"60100"的值调用此方法时,它会"37777777773" "60100" ,但是当我使用"37777777773"这样的字符串进行调用时,它只会显示"0"

我认为您的错误是由与其他编译器(我建议您为GCC编译器)检查编译器引起的,并查看其是否有效。

There are 2 issues 2

printf("%-7.7s\n", "60100");
// should print "60100  ", not "60100" as OP states

printf("%-7.7s\n", "37777777773");
// should print "3777777", not "0".

It appears the compiler is not compliant or something critical is missing from the post. 看来编译器不符合要求,或者帖子中缺少一些重要内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM