beginer help

This is a discussion on beginer help within the C Programming forums, part of the General Programming Boards category; Hi i am very new to C programming i wrote simple program like this and i am using Miracle C ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    2

    beginer help

    Hi i am very new to C programming
    i wrote simple program like this
    and i am using Miracle C compiler , when i compile it , it is showing the programm compailed and no errors,
    and when i run it , the compand prompt window is appearing and disappearing immediately , i am unable to see my hello on the screen , can any one help me



    #include <stdio.h>
    main()
    {
    printf("hello");

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,175
    Read the FAQ
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    2
    when i add the getch in the programm still i am unable to see the result window
    also can any one suggest me which is the best compiler for windows based programming(Windows XP)

  4. #4
    The Hawk Man
    Join Date
    Nov 2005
    Location
    Beaverton, OR USA
    Posts
    13
    Quote Originally Posted by gtsreddy
    Hi i am very new to C programming
    i wrote simple program like this
    and i am using Miracle C compiler , when i compile it , it is showing the programm compailed and no errors,
    and when i run it , the compand prompt window is appearing and disappearing immediately , i am unable to see my hello on the screen , can any one help me



    #include <stdio.h>
    main()
    {
    printf("hello");

    I had the exact same problem (I am also a beginner). You'll want to wewrite the code like this:

    Code:
    #include <stdio.h>
    int main()
    {
          {printf("hello");
           getchar();
           }
    }
    So, what exactly are you adding in? Well, the getchar(); statement is telling the program (when executed) that it needs to stay open instead of just executing and closing. If you don't have the getchar(); in there, the program will close without allowing ample time to read what's on the screen (i.e. viewing data), enter in data, etc.

    Note to advanced C programmers: If I'm wrong about what the getchar(); statement does, please help me better understand my own programming by telling me. Thanks.

  5. #5
    Registered User
    Join Date
    Oct 2005
    Posts
    26
    why are you using the red ones?
    Code:
    #include <stdio.h>
    int main()
    {
          {printf("hello");
           getchar();
           }
    }
    getchar just waits for an input, it reads one character from the input-stream stdio.
    with
    Code:
    #include <stdio.h>
    int main()
    {
          char c;
          printf("hello");
          c = getchar();
    }
    you could use the pressed key.

    you could also use system("pause"); to stop the programm while executing.

    mfg

  6. #6
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,077
    Code:
    system("pause")
    Calls to the system = bad.

    Read the FAQs link that itsme86 posted.
    Sent from my iPadŽ

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    You can also run your program by going to the command prompt and typing in it's name and the command prompt won't close.
    Console programs aren't realy designed to be double clicked which is why they close.

  8. #8
    Registered User
    Join Date
    Sep 2005
    Posts
    92

    Here is a working version of your code

    You had a few errors in the code. I corrected them for you.

    1.You did'nt declear your main function as an int.
    2.You left out "\n" it still compiles even if you leave it out but the screen is clearly presented if you put it in.

    helloPress any key to continue(if you don'nt use \n)

    hello
    Press any key to continue(if you use \n)

    3.Your program was'nt returning anything always put (return 0) if you don'nt want it to return anything.
    4.Last thing was that you did'nt put the end braces. If you open a brace you always have to close it.



    Code:
    #include <stdio.h>
    int main()
    {
    	printf("hello\n");
    return 0;
    }

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Your program was'nt returning anything always put (return 0) if you don'nt want it to return anything.
    return 0 is the default in C99, but you should still put it in.

    You left out "\n" it still compiles even if you leave it out but the screen is clearly presented if you put it in.

    helloPress any key to continue(if you don'nt use \n)

    hello
    Press any key to continue(if you use \n)
    Well, it looks fine with getchar().

    Code:
    #include <stdio.h>
    
    int main(void) {
        printf("Hello, World!\n");
        getchar();
        return 0;
    }
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,822
    > and i am using Miracle C compiler
    Get a real compiler - say dev-c++.
    Search the board, this compiler is a big pile of ........ - it doesn't deserve the name "C compiler".

    If your homework was "write a C compiler", then miracle C would be a passable first attempt.
    As a working compiler for getting real work done, forget it.

  11. #11
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Try Dev-C++, it's a much better compiler.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  12. #12
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    <pedantic>Dev-C++ is an Integrated Development Environment, not a compiler. The compiler it defaults to/is bundled with is mingw, which is a Win32 version of gcc.</pedantic>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. COM Beginer
    By arjunajay in forum Windows Programming
    Replies: 2
    Last Post: 06-01-2006, 10:11 AM
  2. OOP beginer help
    By kernel in forum C++ Programming
    Replies: 10
    Last Post: 05-26-2004, 12:29 PM
  3. Very NEW Beginer, Going mad
    By chrismax2 in forum C++ Programming
    Replies: 24
    Last Post: 04-08-2004, 12:28 PM
  4. Beginer looking for an intro to graphics in C++...
    By scooby13q in forum C++ Programming
    Replies: 17
    Last Post: 06-07-2002, 06:19 PM
  5. Beginer Help with gui
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 04-20-2002, 07:21 PM

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