c - 运行此代码时出现“权限被拒绝”

问题描述 投票:0回答:1

我正在编写一个基本的 C 程序并使用 PuTTY 来执行这个程序。

#include <stdio.h>
#include <stdlib.h>
typedef struct{
        unsigned int *r;
}Image;
int main()
{
    printf("yes\n");
    unsigned int a = 7;
    Image *image;
    image = malloc(sizeof(Image));
    image->r[0] = a;
    printf("r[0] =");
    printf("%d\n",image->r[0]);
    free(image);
    return 0;
}

我执行了它,但出现错误。

$ gcc -c test.c -o test -Wall -std=c11
$ ./test
./test: Permission denied.

我对指针和其他东西不熟悉。所以,我不知道接下来要做什么

c linux putty
1个回答
0
投票

“权限被拒绝”错误通常意味着您没有执行/运行该文件的权限。

您可以使用以下命令检查文件的权限:

ls -l test

这将在输出中显示文件的权限。如果文件没有执行权限(如果权限没有

-x
标志),可以使用命令添加:
chmod +x test

这将为文件添加执行权限。之后,您可以尝试再次执行该文件。

© www.soinside.com 2019 - 2024. All rights reserved.