Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-11-2004, 08:54 AM   #1
LQ Newbie
Registered: Mar 2004
Location: Bangalore, INDIA
Posts: 2

Rep: Reputation: 0
Question Error for a very simple C program

Hi there,

I am a newbie to Linux. The objective of mine is to learn programming on Linux and get rid of Windows. I hate Windows.

In LINUX Answers section of this forum, a simple program of C is published. The program does just a simple printf of some text and nothing else. I am getting an error in Linux.

I have Linux red hat 9. To cross check if C compiler is present, I did a
" which gcc " command in the terminal. I got a reply /usr/bin/gcc . I assume that this means that the compiler is present on the system.

On writing the simple following program:

# include<stdio.h>


I get an error which says :

bash:syntax error near unexpected token '(printf '

I wonder what this means. Help on this regard would be appreciated.

Also, it would be great if people can suggest some good books to buy for programming C on Linux.

Thanks in advance for your help.



P.S : I have logged on as localhost : root. Could this be a reason for the error? Just thinking aloud ..................
Old 03-11-2004, 09:08 AM   #2
Registered: Jan 2004
Distribution: Slackware 10 ; Gentoo ; OpenBSD 3.6
Posts: 101

Rep: Reputation: 15
you have to compile the source code

gcc -o executable filename.c

replace executable with the name you want and filename with the name of the source file.

and then run ./executable

What you are trying to do is run the source code as an executable. C is a compiled language, so you have to run gcc on your source code to turn it into machine language

Old 03-11-2004, 10:24 AM   #3
Mega Man X
LQ Guru
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 64
# include<stdio.h>

You do, realize that all functions in C or C++ has to return a value, unless it's declared as void. main() is not an exception.

# include<stdio.h>

    return 0;
By default, all functions without explicit declaration, will be understood for the compiler as integer. You could declare it as void:
# include<stdio.h>

void main()
and then you don't need to return any value. It's a good programing style to always declare a function explicitly.

# include<stdio.h>

int main()
    return 0;

Last edited by Mega Man X; 03-11-2004 at 10:26 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple C program - error with float J_K9 Programming 2 10-24-2005 11:36 AM
Simple C pow() program, strange error funkymunky Programming 2 06-25-2004 04:20 AM
A simple program on C++ for the linux with an error. Israfel2000 Programming 4 06-16-2004 06:25 PM
simple c program liguorir Linux - Software 4 05-29-2004 06:22 AM
simple program bprasanth_20 Programming 5 10-29-2003 12:55 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:01 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration