-2

i compiled a c code and when I try to run it with ./ command, it gives me -bash: ./hw : Permission denied . please help me. note : i use Mac os Mojave.

C code:

#include <stdio.h>

int main()
{
    int n;
    FILE *ptr;
    ptr = fopen("input.txt", "r");
    fscanf(ptr,"%d", &n);
    printf("%d",n);
    fclose(ptr);
    return 0;
}

Compile command:

gcc -c hw.c -o hw
atline
  • 28,355
  • 16
  • 77
  • 113

2 Answers2

2

Try the command chmod +x hw. This will changes the permissions on the file to allow execution. You should then be able to run it with ./

wc_coder
  • 88
  • 6
0

you are just creating an object file (.o) not an executable.

try compiling with

gcc hw.c -o hw
OznOg
  • 4,440
  • 2
  • 26
  • 35