
I missed the "f" out of if :( ----- Original Message Follows -----
Hi All, Will someone please explain what I need to do to write and run a C program in the bash terminal.I think I may need to tell the terminal to run a c compiler. This is the outcome of a program I copied from a tutorial. john(a)sniffy:~$ #include <stdio.h> john(a)sniffy:~$ int main() bash: syntax error near unexpected token `(' I there is an easy to understand explanation I would like to hear it please.. Regards John
_______________________________________________ wlug mailing list | wlug(a)list.waikato.ac.nz Unsubscribe: http://list.waikato.ac.nz/mailman/listinfo/wlug

Hi, You can not just run a C program, C is not a scripting language as you appear to be trying to use it as, it requires you to first put the source code into a text file and then for it to be complied into an executable before you will be able to run it. Just doing a quick Google search came across this which may help: http://ce.uml.edu/compile.htm Regards, Steven -----Original Message----- From: wlug-bounces(a)list.waikato.ac.nz [mailto:wlug-bounces(a)list.waikato.ac.nz] On Behalf Of jaytee(a)clear.net.nz Sent: Sunday, 28 February 2010 4:10 PM To: jaytee(a)clear.net.nz; Waikato Linux Users Group Subject: Re: [wlug] C program..... I missed the "f" out of if :( ----- Original Message Follows -----
Hi All, Will someone please explain what I need to do to write and run a C program in the bash terminal.I think I may need to tell the terminal to run a c compiler. This is the outcome of a program I copied from a tutorial. john(a)sniffy:~$ #include <stdio.h> john(a)sniffy:~$ int main() bash: syntax error near unexpected token `(' I there is an easy to understand explanation I would like to hear it please.. Regards John
_______________________________________________ wlug mailing list | wlug(a)list.waikato.ac.nz Unsubscribe: http://list.waikato.ac.nz/mailman/listinfo/wlug
wlug mailing list | wlug(a)list.waikato.ac.nz Unsubscribe: http://list.waikato.ac.nz/mailman/listinfo/wlug

Thanks Steve I will have a look and see if I can make some sense of it. Regards John On Sun, 2010-02-28 at 16:18 +1000, Steve Lisson wrote:
Hi,
You can not just run a C program, C is not a scripting language as you appear to be trying to use it as, it requires you to first put the source code into a text file and then for it to be complied into an executable before you will be able to run it.
Just doing a quick Google search came across this which may help:
Regards, Steven
-----Original Message----- From: wlug-bounces(a)list.waikato.ac.nz [mailto:wlug-bounces(a)list.waikato.ac.nz] On Behalf Of jaytee(a)clear.net.nz Sent: Sunday, 28 February 2010 4:10 PM To: jaytee(a)clear.net.nz; Waikato Linux Users Group Subject: Re: [wlug] C program.....
I missed the "f" out of if :(
----- Original Message Follows -----
Hi All, Will someone please explain what I need to do to write and run a C program in the bash terminal.I think I may need to tell the terminal to run a c compiler. This is the outcome of a program I copied from a tutorial. john(a)sniffy:~$ #include <stdio.h> john(a)sniffy:~$ int main() bash: syntax error near unexpected token `(' I there is an easy to understand explanation I would like to hear it please.. Regards John
_______________________________________________ wlug mailing list | wlug(a)list.waikato.ac.nz Unsubscribe: http://list.waikato.ac.nz/mailman/listinfo/wlug
wlug mailing list | wlug(a)list.waikato.ac.nz Unsubscribe: http://list.waikato.ac.nz/mailman/listinfo/wlug

Hi John, You will also need to input the example into a file (preferably named with a .c extension) It looks like you initially tried to type in the commands directly into the bash prompt. Cheers, Wazza. On 28/Feb/2010, at 19:21 , John wrote:
Thanks Steve I will have a look and see if I can make some sense of it. Regards John On Sun, 2010-02-28 at 16:18 +1000, Steve Lisson wrote:
Hi,
You can not just run a C program, C is not a scripting language as you appear to be trying to use it as, it requires you to first put the source code into a text file and then for it to be complied into an executable before you will be able to run it.
Just doing a quick Google search came across this which may help:
Regards, Steven
-----Original Message----- From: wlug-bounces(a)list.waikato.ac.nz [mailto:wlug-bounces(a)list.waikato.ac.nz] On Behalf Of jaytee(a)clear.net.nz Sent: Sunday, 28 February 2010 4:10 PM To: jaytee(a)clear.net.nz; Waikato Linux Users Group Subject: Re: [wlug] C program.....
I missed the "f" out of if :(
----- Original Message Follows -----
Hi All, Will someone please explain what I need to do to write and run a C program in the bash terminal.I think I may need to tell the terminal to run a c compiler. This is the outcome of a program I copied from a tutorial. john(a)sniffy:~$ #include <stdio.h> john(a)sniffy:~$ int main() bash: syntax error near unexpected token `(' I there is an easy to understand explanation I would like to hear it please.. Regards John
_______________________________________________ wlug mailing list | wlug(a)list.waikato.ac.nz Unsubscribe: http://list.waikato.ac.nz/mailman/listinfo/wlug
wlug mailing list | wlug(a)list.waikato.ac.nz Unsubscribe: http://list.waikato.ac.nz/mailman/listinfo/wlug
_______________________________________________ wlug mailing list | wlug(a)list.waikato.ac.nz Unsubscribe: http://list.waikato.ac.nz/mailman/listinfo/wlug

I have a c programming for Linux book if you want to borrow it. Liz On 28/02/2010 7:24 PM, "Warren Boyd" <wazza(a)clear.net.nz> wrote: Hi John, You will also need to input the example into a file (preferably named with a .c extension) It looks like you initially tried to type in the commands directly into the bash prompt. Cheers, Wazza. On 28/Feb/2010, at 19:21 , John wrote:
Thanks Steve I will have a look and see if I can make so...

Its designed for the early stage you are at. It explains all this. Liz On 28 February 2010 19:59, John <jaytee(a)clear.net.nz> wrote:
I think it will be a lot much at this early stage. Thanks for the offer though. Regards John
On Sun, 2010-02-28 at 19:44 +1300, Liz Quilty wrote:
I have a c programming for Linux book if you want to borrow it.
Liz
_______________________________________________ wlug mailing list | wlug(a)list.waikato.ac.nz Unsubscribe: http://list.waikato.ac.nz/mailman/listinfo/wlug

Hi Liz Would you mind bringing it to the next meeting or fixit that you plan on attending please? Regards John On Sun, 2010-02-28 at 20:22 +1300, Liz Quilty wrote:
Its designed for the early stage you are at. It explains all this.
Liz
On 28 February 2010 19:59, John <jaytee(a)clear.net.nz> wrote: I think it will be a lot much at this early stage. Thanks for the offer though. Regards John
On Sun, 2010-02-28 at 19:44 +1300, Liz Quilty wrote: > I have a c programming for Linux book if you want to borrow it. > > Liz
_______________________________________________ wlug mailing list | wlug(a)list.waikato.ac.nz Unsubscribe: http://list.waikato.ac.nz/mailman/listinfo/wlug

Not sure if I missed something here but this is my input/output at the terminal. I am not sure why "a.out" is not recognized. john(a)sniffy:~$ gcc Johntest.c gcc: Johntest.c: No such file or directory gcc: no input files john(a)sniffy:~$ cd Desktop john(a)sniffy:~/Desktop$ gcc Johntest.c john(a)sniffy:~/Desktop$ a.out a.out: command not found john(a)sniffy:~/Desktop$ ls a.out Jim Stafford - Mr. Bojangles.mp3 opencity-0.0.6.2stable freedroidrpg-0.13 Johntest.c john(a)sniffy:~/Desktop$ Johntest Johntest: command not found john(a)sniffy:~/Desktop$ Johntest.c Johntest.c: command not found john(a)sniffy:~/Desktop$ I wonder if I should.. ./configure make makeinstall ??? Regards John
Regards, Steve _______________________________________________ wlug mailing list | wlug(a)list.waikato.ac.nz Unsubscribe: http://list.waikato.ac.nz/mailman/listinfo/wlug

In linux a program must be located in a directory located in the $PATH enviroment variable, or called be called directly with a directory, the most common way is ./a.out (./ being this directory)

Many thanks Ronnie that worked...Whooo whoo I am a programmer :) Regards John On Sun, 2010-02-28 at 19:56 +1300, Ronnie Collinson wrote:
In linux a program must be located in a directory located in the $PATH enviroment variable, or called be called directly with a directory, the most common way is ./a.out (./ being this directory)

On 28 February 2010 20:02, John <jaytee(a)clear.net.nz> wrote:
Many thanks Ronnie that worked...Whooo whoo I am a programmer :) Regards John
Here's my example / suggestions zcat(a)mandela:~$ nano hello.c --- Type the program in the nano editor --- /* hello.c: display a message on the screen */ #include <stdio.h> main() { printf("hello, world\n"); } --- ctrl-X to exit --- zcat(a)mandela:~$ make hello cc hello.c -o hello zcat(a)mandela:~$ ./hello hello, world zcat(a)mandela:~$ Using 'make' rather than 'gcc' gives gcc some sensible default options.. in this case the program that results from 'hello.c' is called 'hello' rather than 'a.out' and as Ronnie already mentioned './hello' to run the program 'hello' which is in the current directory './' If you're going to be compiling anything more complex than a hello world program you may want to install the package 'build-essential' too. -- Disclaimer: By sending an email to any of my addresses you are agreeing that: 1. I am by definition, "the intended recipient" 2. All information in the email is mine to do with as I see fit and make such financial profit, political mileage, or good joke as it lends itself to. 3. I may take the contents as representing the views of your company. 4. This overrides any disclaimer or statement of confidentiality that may be included on your message.

Hi Bruce I am using gedit and have succeeded in getting the output I wanted from the program. I have got the veiw set to "c" but I guess that is just a human viewable thing and plain text would work just the same. Regards John On Sun, 2010-02-28 at 20:24 +1300, Bruce Kingsbury wrote:
On 28 February 2010 20:02, John <jaytee(a)clear.net.nz> wrote: Many thanks Ronnie that worked...Whooo whoo I am a programmer :) Regards John
Here's my example / suggestions
zcat(a)mandela:~$ nano hello.c
--- Type the program in the nano editor --- /* hello.c: display a message on the screen */
#include <stdio.h>
main() { printf("hello, world\n"); }
--- ctrl-X to exit ---
zcat(a)mandela:~$ make hello cc hello.c -o hello zcat(a)mandela:~$ ./hello hello, world zcat(a)mandela:~$
Using 'make' rather than 'gcc' gives gcc some sensible default options.. in this case the program that results from 'hello.c' is called 'hello' rather than 'a.out' and as Ronnie already mentioned './hello' to run the program 'hello' which is in the current directory './'
If you're going to be compiling anything more complex than a hello world program you may want to install the package 'build-essential' too.
-- Disclaimer: By sending an email to any of my addresses you are agreeing that: 1. I am by definition, "the intended recipient" 2. All information in the email is mine to do with as I see fit and make such financial profit, political mileage, or good joke as it lends itself to. 3. I may take the contents as representing the views of your company. 4. This overrides any disclaimer or statement of confidentiality that may be included on your message.

I think someone recommended this to me a while back: http://crasseux.com/books/ctutorial/ Or it may have been another one like it. Anyhow yeah there are lots of tutorials online, was there one that you were looking at? What are you trying to accomplish anyway? John On Sun, Feb 28, 2010 at 7:18 PM, Steve Lisson <SteveL(a)dedicatedservers.net.au> wrote:
Hi,
You can not just run a C program, C is not a scripting language as you appear to be trying to use it as, it requires you to first put the source code into a text file and then for it to be complied into an executable before you will be able to run it.
Just doing a quick Google search came across this which may help:
Regards, Steven
-----Original Message----- From: wlug-bounces(a)list.waikato.ac.nz [mailto:wlug-bounces(a)list.waikato.ac.nz] On Behalf Of jaytee(a)clear.net.nz Sent: Sunday, 28 February 2010 4:10 PM To: jaytee(a)clear.net.nz; Waikato Linux Users Group Subject: Re: [wlug] C program.....
I missed the "f" out of if :(
----- Original Message Follows -----
Hi All, Will someone please explain what I need to do to write and run a C program in the bash terminal.I think I may need to tell the terminal to run a c compiler. This is the outcome of a program I copied from a tutorial. john(a)sniffy:~$ #include <stdio.h> john(a)sniffy:~$ int main() bash: syntax error near unexpected token `(' I there is an easy to understand explanation I would like to hear it please.. Regards John
_______________________________________________ wlug mailing list | wlug(a)list.waikato.ac.nz Unsubscribe: http://list.waikato.ac.nz/mailman/listinfo/wlug
wlug mailing list | wlug(a)list.waikato.ac.nz Unsubscribe: http://list.waikato.ac.nz/mailman/listinfo/wlug _______________________________________________ wlug mailing list | wlug(a)list.waikato.ac.nz Unsubscribe: http://list.waikato.ac.nz/mailman/listinfo/wlug
participants (8)
-
Bruce Kingsbury
-
jaytee@clear.net.nz
-
John
-
John Billings
-
Liz Quilty
-
Ronnie Collinson
-
Steve Lisson
-
Warren Boyd