Thread: Error using Dev-C++ in Windows

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    18

    Error using Dev-C++ in Windows

    Been a long time since using C++ but the error/message I keep getting is from Windows. Add in the fact that my program is working ( mostly ) then I can only assume that it's something completely outside of what I know.

    The message I get is simply "<insert program name> has encountered a problem and needs to close. We are sorry for the inconvenience." The specifics of my program are as follows: it is currently setup as a project with 2 .cpp files and one .h file. One .cpp file is the main file with the other one running function definitions. The .h file just contains the prototypes. There is only one function that I am using, code posted below.

    .h File
    Code:
    #include <conio.h>
    #include <cstdio>
    #include <iostream>
    
    #ifdef FUNCTIONS_H
    #define FUNCTIONS_H
    
    void wait_loop();
    
    #endif
    .ccp File
    Code:
    #include "functions.h"
    
    void wait_loop()
    {
        int input = 1;
        while (input != 13)
        {
            input = getch();
        };
        return;
    }
    Then in the main .cpp file it uses "wait_loop();" exactly like that.

    I've gotten the same error using different variations of this setup. I know that the function itself works because I've used it in other programs and in the original main file. If it's a really simple problem unrelated to Windows, sorry for posting in the wrong forum.

    Thank you.

    EDIT: When I said "works ( mostly )" I meant that the program starts, runs, but fails to close and displays aforementioned message. The main program itself works and as far as I know there should be nothing inside it that should cause this problem.
    Last edited by teck; 06-26-2010 at 06:39 PM. Reason: Missed information

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    This error means you've done something illegal. The most common error is dereferencing an invalid pointer.
    The snippet you shows does not demonstrate the problem.

    Also, don't use magic numbers. A newline is '\n' or '\r' not 10.
    I would also suggest you upgrade your IDE since it's no longer maintained AFAIK.
    A list of IDEs: SourceForge.net: Integrated Development Environment - cpwiki
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    18
    Quote Originally Posted by Elysia View Post
    This error means you've done something illegal. The most common error is dereferencing an invalid pointer.
    The snippet you shows does not demonstrate the problem.

    Also, don't use magic numbers. A newline is '\n' or '\r' not 10.
    I would also suggest you upgrade your IDE since it's no longer maintained AFAIK.
    A list of IDEs: SourceForge.net: Integrated Development Environment - cpwiki
    Thank you for the reply and the tip. I've only showed those snippets because the problem only started to occur once I started separating the code into different files. For confirmation, I will post the main code later.

    Sadly, I do not understand your comment on "magic numbers". Yes, the number 13 used in the wait_loop() may seem arbitrary but that number is used because of the value it represents from getch(); it is the vale used for the <Enter> key.

    Thank you for suggesting getting a new compiler, but I would rather not change compilers unless the compiler is the problem ( if it works, I'm happy with that )


    Main file
    Code:
    #include "functions.h"
    
    using namespace std;
    
    struct room
    {
        int xsize;
        int ysize;
        struct object
        {
            int xloc;
            int yloc;
        } obj[];
          
    };
    
    int main()
    {
        struct room current = { 5 , 5 };
        current.obj[0].xloc = 1;
        current.obj[0].yloc = 1;
        current.obj[1].xloc = 3;
        current.obj[1].yloc = 4;
        cout << current.xsize << " " << current.ysize << "\n";
        cout << current.obj[0].xloc << " " << current.obj[1].xloc << "\n";
        wait_loop();
        current.obj[0].xloc++;
        cout << current.obj[0].xloc << "\n";
        wait_loop();
        return 1;   
    }
    My apologies for the lack of in-code comments.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    This should not compile!
    You have an undefined numbers of objs in room, which you cannot have. You must specify a size! You are trying to access objects that do not exist.

    Magic numbers refers to arbitary numbers in your code that means little or nothing. What does "13" mean, for example? If you used '\r' instead, it would be clear. It doesn't matter that it came from getch, you can ALWAYS compare to chars.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    18
    Quote Originally Posted by Elysia View Post
    This should not compile!
    You have an undefined numbers of objs in room, which you cannot have. You must specify a size! You are trying to access objects that do not exist.

    Magic numbers refers to arbitary numbers in your code that means little or nothing. What does "13" mean, for example? If you used '\r' instead, it would be clear. It doesn't matter that it came from getch, you can ALWAYS compare to chars.
    Thank you for inadvertently assisting me through a long, drawn-out and needless set of comments to the answer of my problem. Perhaps you should compare my comment to an int as you would clearly understand it better and the unnecessary effort required to properly compare it would most likely be appreciated by you.

    Furthermore, without any superior analytical processes your comment would've been completely unhelpful and argumentative in nature.


    P.S. "Cry me a river, build me a bridge, do us all a favour and jump off of it."

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    If you oh so dislike being told things, then perhaps you should simply leave. This forum doesn't "merely" specialize in helping out newbies solve their problems, but also help them write portable and standards compliant code.
    If you don't like it, leave.
    Error 1 error C2133: 'room::obj' : unknown size
    Last edited by Elysia; 06-27-2010 at 06:06 PM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Nov 2007
    Posts
    18
    Elysia
    Helpfulness: 1/10
    Attitude: ........ty, unbecoming, unhelpful
    Additional notes: Easily upset for no apparent reason other than "newbies" making mistakes. . . . . . like what he/she probably made.
    Also thinks of themselves as superior for no clearly defined reason.

    Recommendation: Do not ask Elysia for assistance of any kind.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Exactly. Your attitude is lacking.
    And a PS for you: you are the only one who thinks this way.

    And I fail to see anywhere I've been upset. What I am upset at is your attitude.
    The fact that you managed to get your code up and running in itself is a mystery to me since it's illegal C++.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Further info on Magic Numbers
    Magic number (programming) - Wikipedia, the free encyclopedia

    It is one of what is now days being called an Anti-pattern or Code Smell.
    Anti-pattern - Wikipedia, the free encyclopedia
    Code smell - Wikipedia, the free encyclopedia

    Tim S

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 08:14 AM
  2. how to make a windows application
    By crvenkapa in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 09:59 AM
  3. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 04:44 AM
  4. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM