Menu

same two codes, one giving error other not?

2010-08-24
2012-09-26
  • OZGUR OZZEYBEK

    OZGUR OZZEYBEK - 2010-08-24

    hi!

    I m a beginner at this trying to learn C, I have this .pdf c-in-7-days where
    told me to work on dev-C++. I have the version 4.9.9.2 and win7 as OS. I can't
    understand why this code:

    include <stdio.h>

    main()
    {
    printf("hello world!\n");
    system("pause"); //this line is only needed under windows
    }

    is working for the first time I used it and not in the other times I want to
    use?

    it keeps giving me the same error about the system line as being undeclared.

    when I compile, it puts an x mark on the left of the line and at the bottom
    gives these messages:
    in function 'int main()':
    'system' undeclared (first use this function)
    (Each undeclared identifier is reported only once for each function it appears
    in.)

    I can't figure out a way to solve this since I've only began today.

    I would be grateful if you help me! Thanks...

     
  • cpns

    cpns - 2010-08-24

    If that is truly what the document you referred you suggested as initial code,
    then discard it. It is astounding how many errors, bad-practice, and
    misinformation you can cram into six lines of code. Get a better reference.
    For that matter, a better development tool would help. The recommendation to
    use Dev-C++ may be indicative of the age of the material you are using; there
    are now better choices than perhaps when that was written.

    #include <stdio.h>
    #include <stdlib.h>  // where system() function is declared
    
    int main()  // The only mandated return type for main() in C is int
    { 
        printf( "hello world!\n" ) ; 
        system( "pause" )  ; // Required to prevent the application from terminating 
                            // immediately causing the OS to close its window.
    
        return 0 ;
    }
    
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.