Results 1 to 13 of 13

Thread: C not C++

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2002
    Posts
    296

    C not C++

    I am learning C and when I tried to run a script from a tutorial, iut cant funt the header...

    this is hte code:
    Code:
    #include < stdio.h>
    
    void main()
    {
        printf("\nHello World\n");
    }

    and this is the error..
    Code:
    C:\>gcc c:\c\first.c
    c:/c/first.c:1:20:  stdio.h: No such file Or directory (ENOENT)
    c:/c/first.c: In Function `main':
    c:/c/first.c:4: warning: return Type of `main' is Not `int'
    Kevin Carpenter
    Currently Working in the CAOS (CA Operating System) Group

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Point 1: It's <stdio.h>, not < stdio.h>. Remove the space.

    Point 2: It's int main(void) in C, unless you're using arguments. The associated return 0; for a non-error condition is then also required.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2002
    Posts
    296
    Code:
    C:\>gcc c:\c\first.c
    c:/c/first.c: In Function `main':
    c:/c/first.c:6: warning: `return' with a value, In Function returning void
    c:/c/first.c:4: warning: return Type of `main' is Not `int'
    c:/c/first.c:7:2: warning: no newline at End of file
    Still errors
    Kevin Carpenter
    Currently Working in the CAOS (CA Operating System) Group

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You didn't update your function signature. It's int main(void).

    Also, text files are defined to end with a newline
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2002
    Posts
    296
    Well, This tutorial sucks. Will you show me the hello world program?
    Kevin Carpenter
    Currently Working in the CAOS (CA Operating System) Group

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Code:
    #include <stdio.h>
    
    int main(void) {
        printf("Hello World!\n");
    
        return 0;
    }
    That's what I'd always use.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2002
    Posts
    296
    Code:
    C:\>gcc c:\c\first.c
    c:/c/first.c:7:2: warning: no newline at End of file
    Kevin Carpenter
    Currently Working in the CAOS (CA Operating System) Group

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Put a newline in then.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2002
    Posts
    296
    I'm sorry, I don't know how. This ois my first actual day trying code.
    Kevin Carpenter
    Currently Working in the CAOS (CA Operating System) Group

  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    When you hit "return" in your editor, you add a newline into the file. Text files are defined to end with a newline character for compatibility, and this is what GCC is complaining about.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2002
    Posts
    296
    Oh! I understand...Thanks..But shouldnt the DOS window display "Hello World?"


    Code:
    C:\>gcc c:\c\first.c
    
    C:\>
    It executes but nothing is printed to the screen.
    Kevin Carpenter
    Currently Working in the CAOS (CA Operating System) Group

  12. #12
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    That's because the program fully executes and the console window closes before you get a chance to see anything. You need to put some sort of pause after displaying any information, such as :

    getch();

  13. #13
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    No, you only compile the program, not execute it.

    Code:
    C:\>gcc c:\c\first.c
    
    C:\>\c\first.exe
    Hello, World!
    C:\>
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width