new2c ?

This is a discussion on new2c ? within the C Programming forums, part of the General Programming Boards category; i have a few questions about the code below 1.why does the main() not have return type? 2.what is the ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    5

    Question new2c ?

    i have a few questions about the code below

    1.why does the main() not have return type?

    2.what is the clrscr() used for in this code?

    3.what is the getch() used for in this code?

    Code:
    #include <stdio.h>
    #include <conio.h>
    
    main()
    {
         clrscr();
    
         printf("\n statement.");
    
         getch();
    }

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    > 1.why does the main() not have return type?

    Because it's written incorrectly - main returns an int.

    As for the rest - it's your homework, read a book.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Agh, We need a homework-o-dectector here baaad.
    I don't think it's homework, At least he's a beginner can't hurt
    to help him at least a little.

    clrscr() is used to clear the (console) screen and move the cursor
    back to the upper left. [edit] it's a DEV and Boreland
    specific function.

    getch() fetches any key pressed, If the buffer is empty it waites
    until a key's pressed and returns it.
    Last edited by Travis Dane; 02-19-2003 at 08:35 AM.

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    5

    Unhappy

    sorry for postin Govtcheez i didnt notice this was expert only forum and not for the novice. maybe you wouldnt be such a dillhole if you got out of that cramped lab of yours once in a while.

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    As for the rest - it's your homework, read a book.
    i didnt notice this was expert only forum and not for the novice
    I don't see the connection?

  6. #6
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    Originally posted by braincrash
    sorry for postin Govtcheez i didnt notice this was expert only forum and not for the novice. maybe you wouldnt be such a dillhole if you got out of that cramped lab of yours once in a while.
    Heh, cute.

    It's not an expert forum, but it's not a "do my homework because I'm too lazy to look in a book for 2 seconds" forum, either.

    edit: I'm serious - in the time it took you to write that post, you could have easily looked up the solution in a book. clrcsr isn't a standard function, btw - it wouldn't work in my compiler, for example.

  7. #7
    Registered User
    Join Date
    Feb 2003
    Posts
    5
    this is not homework .I work a 2nd shift factory job and thought id try learning c .maybe one of you guys can give me the address to a beginners forum.

  8. #8
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    *scrathes head* The forum of CPP Home has a beginner section.

  9. #9
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    Alright, sorry I overreacted. This is usually a homework type question. We can answer your questions here.

    1) Since main doesn't have an explicit return type defined there, it defaults to an int, as the standard says it should. It's usually better to actually say it's returning an int, though.

    2) clrscr is a non-standard function that clears the screen and moves the cursor to the upper left corner of the screen. It should be avoided, as it makes your code non-portable when you use non-standard functions (like I said, I use a different compiler than you, so it wouldn't work for me)

    3) getch waits for the next character to be entered. In your code, it's used to pause the program before it ends.

  10. #10
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>maybe one of you guys can give me the address to a beginners forum.
    This is a beginners forum... however you are expected to make attempt at solving your problems before posting here. You'll find its like that in most forums.

    Good luck in your learning efforts

    You might like to read through The FAQ. The answers to your questions are in there
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  11. #11
    Registered User
    Join Date
    Feb 2003
    Posts
    5

  12. #12
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    alright, we believe you. Sorry to be so harsh on you, some of the experienced programmers just want to see people learn on their own.

  13. #13
    Black Mage Extraordinaire VegasSte's Avatar
    Join Date
    Oct 2002
    Posts
    167
    www.cbeginnersunited.com/forums is a good site for beginners, besides cprogramming.com which is obviously excellent!!

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21