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 Discuss UNIX and Linux user interfaces like GNOME, KDE, CDE, and Open Office 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 01:17 PM
interface_file_ff.sh[99]: syntax error at line 1 : `)' unexpected geekforu Shell Programming and Scripting 1 07-07-2008 02:54 AM
syntax error near unexpected token...what caused? joshuaduan Shell Programming and Scripting 8 05-14-2007 10:02 AM
syntax error at line 59: `end of file' unexpected Remi SUN Solaris 4 01-16-2007 02:48 PM
sh: syntax error at line 1: `>' unexpected atiato High Level Programming 2 03-16-2004 07:39 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-27-2008
camzio camzio is offline
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;
}
  #2 (permalink)  
Old 09-28-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,777
Code:
int main( int argc, char **argv)
Try this.
  #3 (permalink)  
Old 09-28-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,322
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
  #4 (permalink)  
Old 09-28-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,777
Franklin -

Some wierd compilers expect two arguments to main. It also could be a shell error, like you think.
  #5 (permalink)  
Old 09-29-2008
camzio camzio is offline
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.
Closed Thread

Bookmarks

Tags
unix commands

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:40 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0