gpt4 book ai didi

c - 我在这个终端做什么? : C Programming

转载 作者:行者123 更新时间:2023-11-30 21:22:02 25 4
gpt4 key购买 nike

这是程序的源代码。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int check_authentication(char *password)
{
if(strcmp(password, "brillig") == 0)
return 1;

if(strcmp(password, "outgrabe") == 0)
return 1;

return 0;
}

int main(int argc, char *argv[])
{
if(argc < 2)
{
printf("Usage: %s <password>\n", argv[0]);
exit(0);
}

if(check_authentication(argv[1]))
{
printf("\n-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
printf(" Access Granted.\n");
printf("-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
}
else
{
printf("\nAccess Denied.\n");
}
return 0;
}

我到底对该图像中的程序做了什么? http://i.imgur.com/7FF9x.png .

当我尝试在 Windows 中运行这个程序时,我无法向其中输入任何内容,但在 UBUNTU 中我认为我正在输入一些内容,但我不太确定发生了什么。

这就是我在 Windows 中运行它时会发生的情况 http://i.imgur.com/0X8ZO.png ,

顺便说一句,该程序的全部目的是演示缓冲区溢出。

<小时/>

Linux 调用,取自屏幕截图:

 $ ./auth_overflow AAAAAAAAAAAAAAAA

Access Denied.

$ ./auth_overflow AAAAAAAAAAAAAAAAAAAAAAAAAAAAA

-=-=-=-=-=-=-=-=-=-=-=-=-=-
Access Granted.
-=-=-=-=-=-=-=-=-=-=-=-=-=-

最佳答案

摘自OP的评论:

Alright, I'm coming from a C++ background this is most likely why this is confusing me. I'm just asking is why can't I input anything when I type the program in codeblocks and hit run and build.

您正在从argv读取输入,它是程序运行时在命令行上提供的参数列表。当您使用 IDE 中内置的“运行”命令时,您的程序将在没有命令行参数的情况下运行(至少默认情况下如此)。不要通过 IDE 运行程序,而是打开命令提示符并手动运行程序。这样,您就可以使用参数运行程序(就像在 Linux shell 中所做的那样),以便 argv 中有一些内容可供您的程序读取。

关于c - 我在这个终端做什么? : C Programming,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11442695/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com