【发布时间】:2016-10-28 18:39:44
【问题描述】:
我有以下代码:
#include <stdio.h>
#include <string.h>
int main(void)
{
char buff[50];
int pass = 0;
printf("\n Enter the password : \n");
gets(buff);
char str[80];
strcat(str, "nw");
strcat(str, "ww");
strcat(str, "io");
strcat(str, "oi");
char str2[22];
strcat(str2, "jm");
strcat(str2, "qw");
strcat(str2, "ef");
strcat(str2, "io");
strcat(str2, "nw");
strcat(str2, "ce");
strcat(str2, "or");
strcat(str2, "ww");
strcat(str2, "qf");
strcat(str2, "ej");
strcat(str2, "oi");
if(strcmp(buff, str))
{
/* we sf as df er fd xc yyu er we nm hj ui ty as asd qwe er t yu as sd df rt ty qw sd password */
printf ("\n Wrong Password \n");
}
else
{
printf ("\n Correct Password \n");
pass = 1;
}
if(pass)
{
printf ("\n\n\n\n\n\n\n%s", str2);
}
return 0;
}
当我运行它时,我得到:
root@images:~# ./root.flag
Enter the password :
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Wrong Password
Segmentation fault (core dumped)
它打印换行符,但不打印 str2 中存储的值。如何让 str2 打印到屏幕上?我对 C 相当陌生,所以我不知道为什么这不起作用。我可能忽略了一些简单的事情。
【问题讨论】:
-
我在您的代码中没有看到
%c转换类型说明符。