compiler does run .exe not

This is a discussion on compiler does run .exe not within the C++ Programming forums, part of the General Programming Boards category; Hi everyone, this is my first post so I'm sorry if I do anything wrong. If I do it isn't/wasn't ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    8

    compiler does run .exe not

    Hi everyone,

    this is my first post so I'm sorry if I do anything wrong. If I do it isn't/wasn't my intention.

    I had to make for school a C++ program, now the program is running quite well if I run it through the compiler. But when I try to tun the .exe it won't run. I tried to run it on several PC's and neither of them wil run the exe. I use Dev-cpp as compiler on all PC's.

    thanks for all, and I'm sorry for my english.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,824
    So beginning with the simple "hello world" program, when you say "doesn't work", what are you seeing?
    - an error message
    - nothing at all
    - a brief flash of a black rectangle before it's gone again

    From a new console (start->Run... and type "cmd" at the prompt to get a console) type
    cd D:\path\to\program
    myprog.exe

    Replacing the obvious with your actual paths and names of course.

    > and I'm sorry for my english.
    Well if you'd said nothing, I would never have known it wasn't your native language
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    8
    ehm it isn't a hello world program, but I get a windows error message. Here is the code maybe it will be helpfull. I admit that the code is a bit messy and th comment s are in dutch ( my native language) as are the variables. The code has to open 2 files with in 1 city-codes and in the other city names. Then the program has to compare them and give for every city code the number of city names that are complement to each other.

    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    //#include <ofstream>
    using namespace std;
    
    const int MAX=3, MAX_P=15;
    
    int main()
    {
        int aantal_codes, teller=0, k=0;
        char stop;
        
        //de codes opslaan en openen
        ifstream code;
        code.open("code.in");
        if (! code.is_open())
        {
         cerr << "Fout: bestand niet kunnen openen."<<endl;
         cin>>stop;
         exit(1);
         
        }
        
        code >> aantal_codes;
        cout<< "er zijn zoveel codes: "<<aantal_codes<<endl;
        
        char code1[MAX][aantal_codes];
        int aantal[aantal_codes], aantal_chars[aantal_codes];
        teller=0;
        while (aantal_codes != teller)
        {
              k=0;
              char *cstr ;
              string code2;
              code>>code2;
              aantal_chars[teller]=code2.size();
              cstr = new char [code2.size()+1];
              strcpy (cstr, code2.c_str());
              
              while (k != code2.size())
              {
                   code1[k][teller]= cstr[k];
                   k++;
              }
              teller++;      
        }
        
        
        //de plaatsen openen en opslaan in array
        int aantal_plaatsen;
        //het ophalen uit het bestand
        ifstream plaats;
        plaats.open("plaats.in");
        if (! plaats.is_open())
        {
         cerr << "Fout: bestand niet kunnen openen."<<endl;
         cin>>stop;
         exit(1);
         
        }
        
        plaats >> aantal_plaatsen;
        cout<< "er zijn zoveel plaatsen: "<<aantal_plaatsen<<endl;
        //opslaan in een array 
        char plaats1[MAX_P][aantal_plaatsen];
        int aantal_p[aantal_plaatsen], aantal_chars_p[aantal_plaatsen];
        teller=0; 
        while (aantal_plaatsen != teller)
        {
              k=0;
              char *cstr_p;
              string code_p;
              plaats>>code_p;
              aantal_chars_p[teller]=code_p.size();
              
              cstr_p = new char [code_p.size()+1];
              strcpy (cstr_p, code_p.c_str());
              
              while (k != code_p.size())
              {
                   plaats1[k][teller]= cstr_p[k];
                   k++;
                    
              }
              teller++;      
        }
        //cout<<aantal_chars[1];
        //array om de score voor de codes bij te houden
        int score_codes[aantal_codes];
        //het vergelijken van de plaatsnamen met de codes
        teller=0;
        int tel_letter=2;
        //cout<<"oke1 ";
        while (teller!= aantal_codes)
        { 
              score_codes[teller]=0;
              
              //cout<<"oke2 "<<endl;
              int tel=0, tel_n=0, tel_k=0, rem=0;
              while (tel!=aantal_plaatsen)
              { 
                    //cout<<"oke3 ";
                    int l=aantal_chars_p[tel];
                    //cout<<l;
                    if (code1[0][teller]==plaats1[0][tel])
                    {//cout<<"oke4 ";
                    if  (aantal_chars[teller]==1)
                    {score_codes[teller]++;/*cout<<"oke6 ";*/}
                    
                    else if((aantal_chars[teller]==2 && code1[1][teller]==plaats1[1][tel])||code1[1][teller]==plaats1[aantal_chars_p[teller]][tel])
                    {score_codes[teller]++;/*cout<<"oke7 "*/;}
                      
                    else if(aantal_chars[teller]==3 && code1[1][teller]==plaats1[1][tel])
                    {
                         /*cout<<"oke15 "*/;tel_letter=2;
                         while (tel_letter!=aantal_chars_p[tel] && rem==0)    
                        { 
                               //cout<<"oke5 ";
                               if (plaats1[tel_letter][tel]==code1[2][teller])
                               {score_codes[teller]++;rem=1;tel_letter++;}
                               else
                               {tel_letter++;}
                        }
                        rem=0;
                    }
                    
                    else if(aantal_chars[teller]==3 && code1[2][teller]==plaats1[l-1][tel])
                    {
                         tel_letter=1;/*cout<<"oke9 ";*/
                         while (tel_k!=aantal_chars_p[tel]-1 && rem==0)
                         { 
                               //cout<<"oke10";
                               if (plaats1[tel_letter][teller]==code1[1][teller])
                               {score_codes[teller]++;rem=1;}
                               else
                               {tel_letter++; tel_k++;}
                         }
                         rem=0;
                         
                    }
                    }tel++;
                    
              }teller++;
        }
        
        //de codes weergeven
        teller=0;
        while (aantal_codes != teller)
        {
              k=0;
              while (k != aantal_chars[teller])
              {
                    cout<<code1[k][teller];
                    k++;  
              }
              cout<<endl;
              teller++;
        }
        //de plaatsen weergeven
        teller=0;
        while (aantal_plaatsen != teller)
        {
              k=0;
              while (k != aantal_chars_p[teller])
              {
                    
                    cout<<plaats1[k][teller];
                    k++;  
              }
              cout<<endl;
              teller++;
        }
        
        //code_scores weergeven
        teller=0;
        while (aantal_codes != teller)
        {
              
              
              cout<<score_codes[teller];
                
              
              cout<<endl;
              teller++;
        }
        ofstream score;
        score.open("code.uit");
        if (! score.is_open())
        {
         cerr << "Fout: bestand niet kunnen openen."<<endl;
         cin>>stop;
         exit(1);
         }
         teller=0;
         
         while (aantal_codes != teller)
         {
               score<<score_codes[teller];
               teller++;
         }
         cout<<"code.uit gemaakt en vol met gegevens";
        cin>>stop;
        return(0);
    }
    If you have some helpfull tips that will help me to make my code more readable and/or faster/more flexible don't hold back.

    thanks for all

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,824
    1. Bump up the compiler errors
    Code:
    $ g++ -W -Wall -ansi -pedantic -O2 foo.cpp
    foo.cpp: In function `int main()':
    foo.cpp:28: error: ISO C++ forbids variable-size array `code1'
    foo.cpp:29: error: ISO C++ forbids variable-size array `aantal'
    foo.cpp:29: error: ISO C++ forbids variable-size array `aantal_chars'
    foo.cpp:41: warning: comparison between signed and unsigned integer expressions
    foo.cpp:66: error: ISO C++ forbids variable-size array `plaats1'
    foo.cpp:67: error: ISO C++ forbids variable-size array `aantal_p'
    foo.cpp:67: error: ISO C++ forbids variable-size array `aantal_chars_p'
    foo.cpp:80: warning: comparison between signed and unsigned integer expressions
    foo.cpp:90: error: ISO C++ forbids variable-size array `score_codes'
    foo.cpp:100: warning: unused variable 'tel_n'
    foo.cpp:29: warning: unused variable 'aantal'
    foo.cpp:67: warning: unused variable 'aantal_p'
    Rather than having
    int array[somevar];
    you should have instead
    int *array = new int[somevar];


    > cstr = new char [code2.size()+1];
    1. You're not modifying the string, so making a copy of it isn't necessary.
    2. You're not doing
    delete [ ] cstr;
    later on in the loop, so it's a memory leak.

    > while (k != code2.size())
    For safety of your arrays, this should be
    while (k < MAX && k != code2.size())

    My guess is you're stepping off the ends of the arrays.

    As for code structure, use some functions, rather than having a main() which is 200 lines long.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,012
    Variable-size arrays is only possible in C99, and not C++, so how did this compile? What compiler are you using?
    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.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,270
    g++ has an extension for variable length arrays in C++. The -pedantic flag makes it pedantic about keeping variable length arrays to C99 instead of C++.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,012
    And this extension is enabled by default?
    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.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,270
    And this extension is enabled by default?
    Yes, and that has proved rather irritating since I tend to compile with -Wall and without -pedantic, and so I may miss the use of the extension in code that I failed to examine closely enough. That said, my experience is only with the MinGW port of g++ 3.4.x. Perhaps it is different for other versions.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Nah, it's the same. By default, GCC is incredibly lenient in everything it does. Comes from a history of having to put up with horrible legacy code, I think.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  10. #10
    Registered User
    Join Date
    Jan 2008
    Posts
    8
    thnx salem the program was stepping out of the arrays. And yes the program could be compiled without any problems, it didn't give any warning nor error. I didn't know that variable arrays aren't supported by most of the compilers but I don't know how to make it work without.
    Thanks for all the replies, it was really helpfull.

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,012
    You need to use dynamic memory - new and delete. I suggest you familiarize yourself with them since this code is non-standard and doesn't work on other compiler than g++.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 10-25-2007, 01:27 PM
  2. How to run a .exe file in MFC GUI?
    By franziss in forum Windows Programming
    Replies: 14
    Last Post: 08-31-2006, 01:38 AM
  3. Replies: 2
    Last Post: 08-29-2006, 09:58 AM
  4. lcc win32 compiler download problems
    By GanglyLamb in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 08-01-2004, 08:39 PM
  5. Replies: 5
    Last Post: 08-05-2002, 08:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21