为什么即使我尝试提供正确的输入,C 也会告诉我这是不安全的?
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char id[8];
printf("Your ID:");
scanf("%s", id);
printf("%s", id);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我假设是因为它可以被利用?为何如此?
此命令用于-printf '%Tc %p\n'提供上次修改文件的日期。
$ find ./ -daystart -mtime -3 -type f ! -mtime -1 -printf '%Tc %p\n'
Tue 08 Mar 2016 12:25:01 NZDT ./compareKPIs-log
Tue 08 Mar 2016 18:04:58 NZDT ./backup_public_html_20160308.tgz
Tue 08 Mar 2016 18:04:58 NZDT ./log-file
Tue 08 Mar 2016 12:25:01 NZDT ./compareKPIs-error
Mon 07 Mar 2016 18:05:02 NZDT ./backup_public_html_20160307.tgz
Run Code Online (Sandbox Code Playgroud)
我想要做的是将日期格式控制为YYYY-mm-dd. 我该怎么做呢?(如果需要,也可以在此处添加 hh:mm:ss)
例如-printf '%TY %p\n'会给我年份%TY:
$ find ./ -daystart -mtime -3 -type f ! -mtime -1 -printf '%TY %p\n' …Run Code Online (Sandbox Code Playgroud) 我有以下代码打印传递给./main. 注意fmt的rodata部分。我已经包含了新行\n,就像在C 中一样,但它没有打印新行,而是打印:
参数数量:1\n
我的代码是:
;main.asm
GLOBAL main
EXTERN printf
section .rodata:
fmt db "Number of parameters: %d \n", 0
section .text:
main:
push ebp
mov ebp, esp ;stackframe
push dword[ebp+8] ;prepara los parametros para printf
push fmt
call printf
add esp, 2*4
mov eax, 0 ;return value
leave ;desarmado del stack frame
ret
Run Code Online (Sandbox Code Playgroud)
我知道在 0 之前和“Number ...”之后包括一个 10fmt会打印它,但我想printf这样做。我用NASM组装代码,然后通过GCC链接它以创建我的可执行文件。
lc (C) 和 c / ls (S) 和 s 在printf()功能上有什么区别?为什么ls(S)转换返回-1?
例子:
printf("%C", '??); // -1
printf("%c", '??); // PRINT
printf("%S", "? ans T"); // -1
printf("%s", "? and T"); // PRINT
Run Code Online (Sandbox Code Playgroud)
在 Mac..
我和我的朋友正在争论%lli和%lld。我一般用%lli, 每次他争辩时都用%lldinprintf和scanf。他声称%lli和%lld不同。
GNU GCC 编译器中的%lli和%lld格式说明符之间有什么区别,还是相同?
我正在printf(const char * format, ...)为一个类实现一个类似的方法,在调用执行实际写入之前,我需要确定它的输出的确切大小,仅给出提供的format和给出的参数。va_listvsprintf()
是否有一个函数可以使用format和va_list来生成输出的确切长度?
我不明白为什么最后 a 等于 1 而 b 等于 0。在我看来,它们应该是一样的。提前致谢。
#include "stdio.h"
int main()
{
int a=0;
int b=0;
a++;
printf("a=%d,b=%d",a,b++);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 目前正在使用 UDP 套接字,我被困在试图了解以下情况。
接收缓冲区定义如下:
char buf[1024];
...
memset(&buf, 0, sizeof(buf));
Run Code Online (Sandbox Code Playgroud)
& 通过调用 recvfrom() 完成
size = recvfrom(sockdf, buf, sizeof(buf), MSG_WAITALL, (struct sockaddr *) &rx, (socklen_t *)&len);
Run Code Online (Sandbox Code Playgroud)
我从远程获取这些数据,使用 Wireshark 确认:
01 fe 00 04 00 00 00 21 53 53 53 5f 54 54 54 54 5f 30 31 32 33 34 35 36 37 10 fe 00 10 02 ac ca fe 00 00 00 00 00 00 00 00
Run Code Online (Sandbox Code Playgroud)
使用一个简单的for循环来识别缓冲区内容,我得到:
for (i = 0; i < size; …Run Code Online (Sandbox Code Playgroud) 我正在尝试打印符号的整数等价物;:?. 和空格,但它不起作用。
printf( "Following symbols ending with a whitespace: - = + / \ ; : ? . [whitespace]\n" );
printf( "%d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n", '-', '=', '+', '/', '\', ';', ':', '?', '.', ' ' );
Run Code Online (Sandbox Code Playgroud)
我已经成功打印了 AZ、az、0-20 和其他符号的整数等价物。但是,当我尝试编译此行时,从分号到右侧的符号似乎存在问题。我从 VS 2019 的命令提示符中收到以下错误。
IntegerValueOfChar.c(29): warning C4129: ' ': unrecognized character escape sequence
IntegerValueOfChar.c(31): error C2143: syntax error: missing ')' before 'constant'
IntegerValueOfChar.c(31): warning C4473: 'printf' : not enough arguments passed for format string
IntegerValueOfChar.c(31): …Run Code Online (Sandbox Code Playgroud) 我正在打印一个需要格式化的字符串。我想使用存储在另一个变量中的一组字符来打印 printf,但我不确定如何执行此操作。
my $max_len = max map length, keys %hash;
printf ("%s %s\n", $string1, ":$string2");
Run Code Online (Sandbox Code Playgroud)
显然这是输出,string1 :string2但我想要的是第一列的总宽度为 $max_len。我怎样才能做到这一点?