Menu

Simple problem which involves runtime and C

Paul
2009-01-29
2012-09-26
  • Paul

    Paul - 2009-01-29

    My problem is when I run a simple C program.

    I use a printf function to print output and scanf to read the input.

    Here is a sample of what the code looks like in practice

    void main()
    {

    int no;
    printf("Enter a number: ");
    scanf("%d", &no);
    printf("\nHere is your number: %d", no);

    }

    OK, the issue is once I compile and run the environment closes the DOS window immediately after it reads input with scanf. For no apparent reason it will not allow that last printf statement.

    Just to make sure if I wrote the program properply I ran the executable outside DEVC++ and everything worked fine.

    Please help!!!!

     
    • cpns

      cpns - 2009-01-29

      > For no apparent reason it will not
      > allow that last printf statement.

      It is normal behaviour for a GUI OS to close an applications window as soon as the program terminates. That is all that happened, your program terminated.

      Clifford

       
    • Wayne Keen

      Wayne Keen - 2009-01-29

      Please look at the thread in this very forum with the title

      "Please Read Before Posting a Question"

      Your question is answered there.

      Wayne

       

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.