Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我在这个终端里做什么?:C编程_C_Ubuntu - Fatal编程技术网

我在这个终端里做什么?:C编程

我在这个终端里做什么?:C编程,c,ubuntu,C,Ubuntu,这是程序的源代码 #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 m

这是程序的源代码

#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;
 }
根据OP的评论:

<> P>好的,我来自C++背景,这很可能是为什么 这让我很困惑。我只是问,为什么我不能输入任何东西,当我 在代码块中键入程序,然后点击run and build


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

?你说“我对这个项目做了什么”是什么意思?为什么你不能用调试器跟踪程序的执行,或者添加打印语句?我和你一样困惑,因为你是我的朋友…你。。。在命令行上给出参数?我认为OP意味着,当我用一些特定参数调用它时,为什么我会出现错误的行为。。。虽然参数并没有那么长,但文本的效果要比屏幕截图好terminal@Loseb:如果程序没有问题,为什么要在这里发布?这里肯定有个问题。对您看到的症状最可能的解释是您意外地运行了旧版本的程序。您确定在修改源后在两个系统上都重新编译了它吗?检查
.c
.exe
文件的时间戳。是的,这就是我问题的答案。
 $ ./auth_overflow AAAAAAAAAAAAAAAA

Access Denied.

 $ ./auth_overflow AAAAAAAAAAAAAAAAAAAAAAAAAAAAA

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