Tag: printf

如何使用格式字符串攻击

假设我有以下代码: #include #include #include int num1 = 0; int main(int argc, char **argv){ double num2; int *ptr = &num1; printf(argv[1]); if (num1== 2527){ printf(“Well done”); } if(num2 == 4.56) printf(“You are a format string expert”); return 0; } 我正在努力了解如何正确行事,但我无法用互联网上的指南来组织我的思想。 它假设是这样的: ./Program %p %p %p %p 然后 ./Program $( printf “\xAA\xAA\xAA\xAA”) %.2523d%n 我只是想不出来,请帮我解决这个问题。 其重点是通过prinft函数将字符串利用到正在运行的程序中。 我需要得到“做得好”和“你是格式字符串专家”才能打印出来。 就我而言,通过Linux终端/ […]

(GCC)美元符号printf格式字符串

我在用C编写的源代码中看到了以下行: printf(“%2$d %1$d”, a, b); 这是什么意思?

为什么C中的printf()不能同时打印两个64位值?

我正在研究一个32位系统。 当我尝试在单个printf中打印多个64位值时,它无法再打印任何值(即第2,第3 ……)变量值。 例: uint64_t a = 0x12345678; uint64_t b = 0x87654321; uint64_t c = 0x11111111; printf(“a is %llx & b is %llx & c is %llx”,a,b,c); 为什么这个printf不能打印所有值? 我正在修改我的问题 printf(“a is %x & b is %llx & c is %llx”,a,b,c); 通过这样做的结果是:a是12345678&b是8765432100000000&c是1111111100000000 如果我没有正确打印一个值,那为什么其他的价值才会变化?

在c printf()返回

在c printf()中返回什么?

在嵌入式C中使用带有sprintf()的浮点数

大家好,我想知道float变量是否可以在sprintf()函数中使用。 就像,如果我们写: sprintf(str,”adc_read = %d \n”,adc_read); 其中adc_read是一个整数变量,它将存储该字符串 “adc_read = 1023 \n” 在str (假设adc_read = 1023 ) 如何使用float变量代替整数?

C – 跳过用户输入?

我想要一个菜单​​,你可以从中选择一些动作。 问题是,当我们选择一个,并按下“返回”键时,将跳过应该是下一步的用户输入命令。 这是为什么 ? 代码是: #include #include int main(int argc, char *argv[]) { int choice; do { printf(“Menu\n\n”); printf(“1. Do this\n”); printf(“2. Do that\n”); printf(“3. Leave\n”); scanf(“%d”,&choice); switch (choice) { case 1: do_this(); break; case 2: // do_that(); break; } } while (choice != 3); return(0); } int do_this() { char name[31]; printf(“Please enter a […]

为什么我的输出仅在打印后再打印?

这里有趣的小虫子: if (host != NULL) { printf(“hi”); } else { printf(“FAIL”); } return 0; 根本不打印任何东西,但是: if (host != NULL) { printf(“hi”); } else { printf(“FAIL”); } fprintf(stdout, “\n%s\n”, (char *)&additionalargs); return 0; 版画 嗨 ABC 有人知道为什么吗?

没有’\ n’的printf()在libev 中不起作用

首先发布代码: #define EV_STANDALONE 1 #include #include “ev.c” ev_timer timeout_watcher; struct ev_loop* loop; static void timeout_cb (EV_P_ ev_timer *w, int revents) { // puts(“timeout”); printf(“timeout”); ev_timer_again(loop, w); } int main (void) { printf(“hello, world.”); loop = EV_DEFAULT; ev_timer_init (&timeout_watcher, timeout_cb, 5.5, 0.); timeout_watcher.repeat = 2.0; ev_timer_start (loop, &timeout_watcher); ev_run (loop, 0); return 0; } 跑步时发生了奇怪的事情:虽然是printf(“hello, world.”); […]

为什么程序不执行最终的printf语句?

我无法弄清楚为什么程序控制没有到达第三个printf,就在for循环之后。 为什么不打印第三张printf ? 如果我将for循环更改为while循环,它仍然不会打印。 这是程序和输出: main() { double nc; printf (“Why does this work, nc = %f\n”, nc); for (nc = 0; getchar() != EOF; ++nc) { printf (“%.0f\n”, nc); } printf (“Why does this work, nc = %f”, nc); } 输出是: Why does this work, nc = 0.000000 test 0 1 2 3 4

将int转换为double

我运行这个简单的程序,但是当我从int转换为double ,结果为零。 然后,零的sqrt显示负值。 这是一个在线教程的例子,所以我不确定为什么会这样。 我试过Windows和Unix。 /* Hello World program */ #include #include main() { int i; printf(“\t Number \t\t Square Root of Number\n\n”); for (i=0; i<=360; ++i) printf("\t %d \t\t\t %d \n",i, sqrt((double) i)); }