Thread: Help with vanishing screen

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    22

    Help with vanishing screen

    I posting this message seeking some assistance on an issue I am experiencing. I have been helping a friend with writing C programs as he is currently in school. I have taken C a while ago, and I experienced this same problem. However, I do not remember what the fix is.

    Problem:

    I am using Borland C++ for my compiler. The programs compile fine with no errors. When I run the program, the screen comes up asking for the user's input. I type the input, press enter, and the screen immediately disappears. When I took the class, I used fflush() or getchar(). I have tried these functions and they don't solve this problem. From previous conversations with more experienced C programmers, I realize that using fflush is not a good programming practice. Therefore, I would rather learn the right way.

    Unfortunately, I do not have the code handy to paste into this post, but if you need it, I can certainly add it later this evening. I would like to mention that it does this on all the C programs I have attempted to compile and run on two different high powered computers. If you need any additional information, please let me know.

    I am hoping it might just be a setting with the Borland software or some kind of C function I can add that will prevent this from happening.

  2. #2
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    I think what you are describing is your program asking for input and then displaying the answer, but closing before you can read anything. To fix this try adding the system("pause") like this:
    Code:
    int main(void)
    {
      //code here
      system("pause");
      return 0;
    }
    This way, before you program exits it will pause and say press any key to continue.

    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    22

    Thanks

    Thanks for the suggestion. What you described is exactly the problem I am experiencing. I will certainly try adding that code to see if that will delay the termination so I can view the results.

  4. #4
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Make sure to post in the right forum next time. This is not a game programming question.
    Do not make direct eye contact with me.

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    22
    I apologize Lurker for posting in the wrong forum. I was reading the game programming forum and forgot where I was when I posted.

  6. #6
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    I have another suggestion just in case Sean's doesnt work.

    Since you are using Borland C++, you might want to consider conio.h. Borland put a function in there called getch() which acts similar to getchar().

    Just throw in a getch() and it should do the trick:

    int main (void)
    {
    ....code....

    getch();
    return 0;
    }
    My Website

    "Circular logic is good because it is."

  7. #7
    Registered User
    Join Date
    Feb 2002
    Posts
    22
    Thanks for the suggestion DavidP. I will give this a shot as well. I do appreciate the response.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Render text
    By Livijn in forum C++ Programming
    Replies: 6
    Last Post: 07-06-2007, 03:32 PM
  2. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 04:56 PM
  3. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 10:18 PM
  4. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM
  5. Converting from Screen to World Coordinates
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 05-11-2004, 12:51 PM