The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Special Forums > UNIX Desktop for Dummies Questions & Answers
Google UNIX.COM


UNIX Desktop for Dummies Questions & Answers Questions regarding GNOME, KDE, CDE, Open Office, etc go here. All UNIX and Linux Newbies Welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
"syntax error near unexpected token `fi' " GIC1986 SUN Solaris 4 09-19-2008 09:17 AM
interface_file_ff.sh[99]: syntax error at line 1 : `)' unexpected geekforu Shell Programming and Scripting 1 07-06-2008 10:54 PM
syntax error near unexpected token...what caused? joshuaduan Shell Programming and Scripting 8 05-14-2007 06:02 AM
syntax error at line 59: `end of file' unexpected Remi SUN Solaris 4 01-16-2007 11:48 AM
sh: syntax error at line 1: `>' unexpected atiato High Level Programming 2 03-16-2004 04:39 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-27-2008
Registered User
 

Join Date: Sep 2008
Posts: 2
line 3: syntax error near unexpected token `('

Hi All
I've used UNIX in the past experimenting with commands through terminal but thats about it. Im now currently teaching myself "C".
Using a book from the library, the first chapter asks you run and compile your program from a command-line prompt. As you will see the program is very simple, please see below, but I am scratching my head as to why there is any problem with this when running this through UNIX. I coded the below with a textEdit and I am also using Xcode and it builds succesfully, but when I put it through UNIX I get the following

./hello.c: line 3: syntax error near unexpected token `('
./hello.c: line 3: `int main (void)'

I have searched your forums and Google and although there is much regarding the title, none covers something so simple as this one. I would very much appreciate if you could advice me what this is?

Many thanks for your time and reading,
Camzio

Quote:

#include <stdio.h>

int main (void)
{
printf ("Hello World!");

return 0;
}
Reply With Quote
Forum Sponsor
  #2  
Old 09-28-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
Code:
int main( int argc, char **argv)
Try this.
Reply With Quote
  #3  
Old 09-28-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,331
The code should work. Have you compiled your program?

First you have compile your program with:

Code:
cc hello.c -o hello
And the you can run it with:

Code:
./hello
Regards
Reply With Quote
  #4  
Old 09-28-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
Franklin -

Some wierd compilers expect two arguments to main. It also could be a shell error, like you think.
Reply With Quote
  #5  
Old 09-29-2008
Registered User
 

Join Date: Sep 2008
Posts: 2
Resolved

Many thanks to all those who replied, it actually worked by using, as advised cc hello.c -o hello and then running ./hello the book says to type gcc -g -o hello hello.c. Once again thank you.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 08:28 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0