我的代码不会在" exit;" 之前运行最后一行,我不知道为什么.我之前试图增加printf $fh一条线exit,但这也没有用; 它不会打印任何一行.除了退出前的最后一个打印语句外,其他所有内容都打印正常.
任何线索为什么会这样?或者更好的是,如何修复或解决它?
if($i>0 && $i<3)
{
printf $fh "Partial match found.\n";
if($matched_uid){printf $fh "UID #: ".$arguid." exists.\n";}
if($matched_id){printf $fh "ID #: ".$argid." exists.\n";}
if($matched_uname){printf $fh "Username: ".$arguname." exists.\n";}
printf $fh "Aborting.";
exit;
}
Run Code Online (Sandbox Code Playgroud)
编辑:
我复制的部分代码包含此内容
select $fh; $| = 1; #set auto flush
Run Code Online (Sandbox Code Playgroud)
也许这就是我的结果无法复制的原因....
在Matlab中,以下内容在图例中的指定行上生成黑色:
leftAxis = sprintf('left y-axis','Color','r');
leg = legend([.. bla bla ..], sprintf('test [%s]', leftAxis), etc... );
Run Code Online (Sandbox Code Playgroud)
我想要实现的是图例中同一行上的两种颜色.(所以在这个例子中,部分'test'应该是黑色而部分'left y-axis'应该是红色的.
我尝试过的:
想象一下我的意思的图片:

#include <stdio.h>
int main()
{
printf(5 + "Good Morning\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
代码打印出晨.代码应该打印早上还是应该显示未定义的行为?
尝试从KandR的另一个例子,我有以下C代码:
#include <stdio.h>
int main(){
double nc = 5;
printf("%*.0f",nc);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
打印5然后它从左到右继续移动(打印空白字符),然后按下Ctrl+ C)继续移动直到停止.当我改变它的printf行时printf("%.0f",nc)它按预期工作,即它只打印5并停止.
根据http://www.cplusplus.com/reference/cstdio/printf/ printf的语法是:
%[flags] [width] [.precision] [length]说明符.
我改变了[width]to,*这样printf就不会限制输出中的数字.
1)为什么在停止之前一直打印空白字符?
2)当我没有给出任何宽度时,
printf默认情况下会假设什么?3)我还修改了上面的代码设置
nc = 500,然后printf除了连续的空白字符外不打印任何东西!
当我将其更改为500.00时,它会打印500,之后会一直打印空白字符,直到停止为止.我设置时为什么没有输出nc=500?为什么设置时有输出nc=500.00?
问题是 :
如何使用
printf()?实现可变字段宽度?也就是说,%8d应该在运行时指定宽度.
基于上面的问题,我在互联网上遇到了一些C代码,但由于我是C编程的新手,我无法对代码做出正面或反面.我发布以下代码:
#include <stdio.h>
int main()
{
const char text[] = "Hello world";
int i;
for ( i = 1; i < 12; ++i )
{
printf("\"%.*s\"\n", i, text);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我试图在64位Linux上的GCC扩展内联ASM中输出相同的字符串两次.
int main()
{
const char* test = "test\n";
asm(
"movq %[test], %%rdi\n" // Debugger shows rdi = *address of string*
"movq $0, %%rax\n"
"push %%rbp\n"
"push %%rbx\n"
"call printf\n"
"pop %%rbx\n"
"pop %%rbp\n"
"movq %[test], %%rdi\n" // Debugger shows rdi = 0
"movq $0, %%rax\n"
"push %%rbp\n"
"push %%rbx\n"
"call printf\n"
"pop %%rbx\n"
"pop %%rbp\n"
:
: [test] "g" (test)
: "rax", "rbx","rcx", "rdx", "rdi", "rsi", "rsp"
);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
现在,字符串只输出一次.我尝试了很多东西,但我想我错过了关于调用约定的一些注意事项.我甚至不确定clobber列表是否正确,或者我是否需要保存和恢复RBP和RBX.
为什么字符串不输出两次? …
我正在尝试使用转义双引号打印文件内容.
# read file contents from ${filename}
# - escape double quotes
# - represent newlines as '\n'
# print the result
echo "my file contents: \"${out}\""
Run Code Online (Sandbox Code Playgroud)
例如,如果我的文件是
<empty line>
console.log("hello, world");
<empty line>
Run Code Online (Sandbox Code Playgroud)
它应该打印
my file contents: "\nconsole.log(\"hello, world\");\n"
Run Code Online (Sandbox Code Playgroud)
我试图使用带有%q格式说明符的printf,但是它存在删除尾随空格的问题.
我正在查看以下代码:
#include <stdio.h>
#include <inttypes.h>
int main()
{
uint32_t total = 0;
printf("\tTotal: %"PRIu32"\n\n", total);
return total;
}
Run Code Online (Sandbox Code Playgroud)
如何PRIu32适应printf语法?我的意思是,我可以猜测,Iu32可能意味着"整数无符号32位".但是,我不确定找到哪种形式man 3 printf可以容纳引号之外的变量 - 以及如何将其推广到引号外的其他语句.
我正在尝试使用printf来获得以下编程输出:
- 20
- 15
- 10
- 5
0
+ 5
+ 10
+ 15
+ 20
Run Code Online (Sandbox Code Playgroud)
关键规格是:
到目前为止,我还没有能够提出一个能给我预期结果的printf语句.我最接近的是:
for(int i = -20; i <= 20; i+=5)
{
printf("%-+4d \n", i);
}
Run Code Online (Sandbox Code Playgroud)
产生:
-20
-15
-10
-5
+0
+5
+10
+15
+20
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点,而不必做任何繁琐的字符串操作?
#include <stdio.h>
#define PREC 4
int main()
{
long l = 12;
printf("%PRECld", l);
}
Run Code Online (Sandbox Code Playgroud)
我将如何使用它PREC来定义所需的精度?即预期的产出是0012。目前正在印刷%PRECld。