0
#include <stdio.h>

int main(void)
{
    printf("hello , world");
}

$ clang welcome.c 
$ ./welcome.c
./welcome.c: line 4: syntax error near unexpected token `('
./welcome.c: line 4: `int main(void)'

1 Answer 1

1

The code posted above compiled without error for me. Is it possible that you didn't cut and paste the original code from your development environment exactly as it appears?

Errors like this usually come from a typo or something else that doesn't belong somewhere, such as a stray semicolon.

[edit-gotta stop answering half asleep. ;-) ]

Now that I've looked carefully at what you did, I understand the problem.

First, you ran the command clang welcome.c. This created the executable file called hello. You should consider using the make command in the future.

Next, you ran the command ./welcome.c. This told the system to attempt to execute the source code file welcome.c. So, it did what it was told and then crashed and burned on the 4th line of the source code file.

Instead, you want to execute the executable file, ./welcome, not welcome.c. C source code files are not intended to be executed directly. They need to be compiled and the executable files generated.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

3
  • I am still getting the same error even if I type the code or copy paste it. Not sure where I am going wrong. Because of this error not able to try any other code. Thanks for your reply.
    – Kirti K
    Jan 18, 2019 at 5:19
  • See edited answer.
    – Cliff B
    Jan 18, 2019 at 6:19
  • Thank you so much for your help. I was doing such a silly mistake.
    – Kirti K
    Feb 2, 2019 at 7:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .