#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(int argc, char *argv[]){
char a[5];
char b[10];
strcpy(a,"nop");
gets(b);
printf("Hello there %s. Value in a is %s.\n",b,a);
exit(0);
}
我需要让程序打印 你好 Leslie。 a 中的值是正确的。
我尝试对程序执行任意输入,但我似乎无法让它忽略某些输入。例如,如果我运行程序并输入:
Leslie\\\\Correct
程序将输出 Hello there Leslie\\\\Correct。 a 中的值是正确的。
如何使用缓冲区溢出从第一部分中删除 \\\\Correct
?
最佳答案
%s
查找空终止字符,即“\0”,以便知道字符串何时结束。所以你需要输入“Leslie\0---Correct”来得到你想要的格式。 gets 将在输入的末尾添加另一个 \0
所以你需要记住这不会真正导致 BO ...
抱歉格式错误,我正在打电话。
关于c - 使用缓冲区溢出打印特定文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29314575/