Results 1 to 6 of 6

Thread: Problem with 'Program in C' (issue 17)

  1. #1
    Join Date
    Mar 2006
    Beans
    52

    Angry Problem with 'Program in C' (issue 17)

    I don't know if this is the right forum for this particular problem, but I'm sure somebody will put me right if it isn't

    I'm trying to follow the 'Program in C' series which started in issue 17, but I've fallen over at the first hurdle.

    I've entered the 'Hello world' listing in Gedit; -

    01. #include <stdio.h>
    02.
    03. /***********************************
    04. * Main function gets called when *
    05. * the application is launched *
    06. ***********************************/
    07. int main()
    08. {
    09. // Say something to the audience
    10. printf("Hello world\n");
    11. return 0;
    12. }

    I can't see anything wrong with what I've typed in, but when I try to compile it, I get the following error messages;-

    john@john-desktop:~$ gcc -Wall -W -Werror c-try.c -o c-try
    c-try.c:1: error: expected identifier or ‘(’ before numeric constant
    c-try.c:1: error: stray ‘#’ in program
    john@john-desktop:~$

    Out of interest, I installed Anjuta and tried compiling the listing in it; I got the same errors, so presumably there is something wrong with the program I'm trying to compile.

    Can anybody help, please. I'm not new to programming, but this has got me beat.

    Thanks,

    John

  2. #2
    Join Date
    Dec 2007
    Location
    Okinawa, Japan
    Beans
    129
    Distro
    Xubuntu 9.04 Jaunty Jackalope

    Re: Problem with 'Program in C' (issue 17)

    I just tried that and got the expected output:
    jason@apollo:~$ ./c-try
    Hello world
    You aren't actually typing in "01." and "02." and so forth are you?
    Me and U(buntu) - My blog about Ubuntu and related issues.

  3. #3
    Join Date
    Mar 2006
    Beans
    52

    Re: Problem with 'Program in C' (issue 17)

    You aren't actually typing in "01." and "02." and so forth are you?
    Er, yes I did. I take it I'm not supposed to.

    Thanks very much for that, I'll try again.

    John

  4. #4
    Join Date
    Mar 2006
    Beans
    52

    Smile Re: Problem with 'Program in C' (issue 17)

    It works without the line numbers. Excellent.

    I haven't seen any other posts regarding this problem, so presumably I'm the only person daft enough to enter the listing as shown, but I'd have thought it would have been a good idea for the author to make it clear in the article that line numbers weren't required. Make it idiot-proof, with me being the idiot in question.

    Oh well. Thank goodness for the forum and the people, like yourself, who are good enough to put simpletons like me back on track.

    Thanks again.

    John

  5. #5
    Join Date
    Dec 2007
    Location
    Okinawa, Japan
    Beans
    129
    Distro
    Xubuntu 9.04 Jaunty Jackalope

    Re: Problem with 'Program in C' (issue 17)

    Ha ha! No worries, you are quite welcome.

    BTW, if you decide to get serious about C, let me suggest The C Programming Language by Brian Kernighan and Dennis Ritchie.

    This is the book known as "K&R" and is basically the Bible for C - and a darn good primer for programming in general I think.
    Me and U(buntu) - My blog about Ubuntu and related issues.

  6. #6
    Join Date
    Nov 2008
    Location
    Romania
    Beans
    87

    Wink Re: Problem with 'Program in C' (issue 17)

    You can also start with 'C for Dummies, 2nd edition'.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •