No Permission to run C program

Asked by Bharat B. Sahni

I am not able to run the C Program

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu gcc-defaults Edit question
Assignee:
No assignee Edit question
Solved by:
Karunesh Johri
Solved:
Last query:
Last reply:
Revision history for this message
Bharat B. Sahni (bharatbsahni-msn) said :
#1

I am new for the Linux
I want to learn C Programming
I have installed build-essential
To run the following program I took the following steps;

In Terminal window;

1. Sudo gedit main.c
2. Wrote the follwong program in gedit main.c file;
 #include <stdio.h>

int main()
{
printf("Hello, world\n");
return 0;
}
3. saved it
4. then wrote;
                  $ cc -c main.c
5.then wrote;
  ./main.c
6. I get the message;
     bash: ./main.c: Permission denied

Please help

Revision history for this message
Best Karunesh Johri (kj-softprayog) said :
#2

Skip the -c flag. Try

cc main.c
./a.out

The cc command compiles main.c into an executable file a.out by default. In case you want it to have another name,

cc main.c -o main
./main

Revision history for this message
Bharat B. Sahni (bharatbsahni-msn) said :
#3

Thanks, Karunesh,

This have sold the problem

Revision history for this message
Bharat B. Sahni (bharatbsahni-msn) said :
#4

Thanks Karunesh Johri, that solved my question.