Thread: funny error when my app terminates!

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    2

    funny error when my app terminates!

    hopefully someone can help me!! i have a short bit of code that for some reason, causes a runtime error when my app terminates. everything works fine with the program, except for when it closes. the error message is like this...

    run-time check failure #2 - stack around the variable <blahblah> was corrupted!!

    my section of code is in this format...

    int main(void)
    {
    short int sdone = 0;

    do
    {
    short int schoice;
    /* get input from user */

    if (schoice == 1)
    ...
    else if (schoice == 2)
    ...
    else if (schoice == 3)
    sdone = 1;
    }
    while (!sdone);

    return 0;
    }

    everytime the user presses 3, i have the app close. but everytime when 3 is pressed, this error pops up. i am programming this app in visual studio .net professional!! please can anyone help me!! thanks!!

  2. #2
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    Try putting the schoice variable declaration at the top where it belongs with sdone. Also, if that does not solve it, we need to see the ...s and the get input comments. Also, use code tags.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Unfortunately, you missed out all the code which actually modifies any variables, so it's impossible to tell what you've done wrong.

    Don't forget the code tags next time you post.
    Hint - read the "read before posting code thread"
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Aug 2004
    Posts
    2

    well i seemed to fix it

    well for some reason it has to do with my variable types. schoice is a short. when i changed it to an int everything worked fine!! im not overflowing the variable. the highest value that gets stored in schoice is 3. WEIRD!! thanks alot for your guys responses!! ill be sure and tag my code next time!!

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    "I did this and the problem went away" fixes are not really that good if you still don't understand what is going on.

    If you want a real answer that will help you avoid the same problem from ever happening again, I suggest you post some real code you compiled and tried, then we can comment more fully and accurately.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. non-MFC DLL with MFC app question.
    By Kempelen in forum Windows Programming
    Replies: 10
    Last Post: 08-20-2008, 07:11 AM
  2. best program to start
    By gooddevil in forum Networking/Device Communication
    Replies: 4
    Last Post: 05-28-2004, 05:56 PM
  3. Need help migrating console app to windows app
    By DelphiGuy in forum C++ Programming
    Replies: 1
    Last Post: 03-14-2004, 07:05 PM
  4. pasword app
    By GanglyLamb in forum C Programming
    Replies: 2
    Last Post: 06-07-2003, 10:28 AM
  5. How do I make my Linux app standalone?
    By Joda in forum C++ Programming
    Replies: 2
    Last Post: 11-27-2002, 04:53 AM