News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

console app in windows xp doesn't run properly

Started by itbhp, October 09, 2008, 06:38:52 PM

Previous topic - Next topic

itbhp

I have written a simple console app that writes the sum of even elements of fibonacci sequence lesser than an upper bound.


#include <iostream>
#include <vector>

using namespace std;

vector<int> lista_fibonacci(int upper_bound)
{
    vector<int> lista;
    lista.push_back(1);
    lista.push_back(1);
    int i=1;
    while (lista[i-1]+lista[i] < upper_bound)
    {
        lista.push_back(lista[i-1]+lista[i]);
        i++;
    }
    return lista;
}

int Sum_even(vector<int> lista)
{
    int sum = 0;
    for (int i=0; i<lista.size(); i++) if((lista[i]%2)==0) sum+=lista[i];
    return sum;
}

void stampa(const vector<int> lista)
{
for(int i=0; i<lista.size();i++)
  cout << lista[i] << " ";
cout << endl;
}

int main()
{
    vector<int> lista_fib;
    int upper_bound=40000;
    lista_fib=lista_fibonacci(upper_bound);
    cout<<endl<<"Valori della serie di Fibonacci minori di "<<upper_bound<<endl;
    stampa(lista_fib);
    cout<<endl<< "La somma dei valori pari della serie di Fibonacci minori di "<<upper_bound<<" e': " << Sum_even(lista_fib)<<endl;
    return 0;
}



I didn't start a project in CodeBlocks but I created only a simple cpp file. It builds right but when I try to run it in CodeBlocks, it appears a command window with these lines:

Process returned 0 <0x0> execution time : 0.109 s
Press any key to continue.

Searching the forum I discovered that these lines are related with a file "cb_console_runner.exe" that CodeBlocks calls when it runs console app.

The problem is that launching program from command line window after compiling works fine but running it in codeblocks doesn't, that is: it doesn't show my program output but only those lines.

How can I fix this?

Thanks for help,
Paolo

P.S.: I use Windows Xp Home Service Pack 3 and CodeBlocks 8.02 (codeblocks-8.02mingw-setup.exe).
"Anyone who has never made a mistake has never tried anything new."
A.E.

odubtaig

Did you specifically create a console application project? It doesn't read like you did. I've not had this problem with the same release.

itbhp

Quote
I didn't start a project in CodeBlocks but I created only a simple cpp file.

By the way even starting a console application project the problem remains.

Probably I wasn't clear: the error is that by clicking the "Run" button in Codeblocks  it appears a command window with these lines:

Process returned 0 <0x0> execution time : 0.109 s
Press any key to continue.

even if the file.exe exists and I get the right output in a different command window I opened.

"Anyone who has never made a mistake has never tried anything new."
A.E.

Jenna

Your file works fine for me.


Pleae turn on full commandline logging :"Settings -> Compiler and debugger... -> Global compiler settings -> Other settings(rightmost tab)" "Compiler logging" to "Full commandline" .

And the run it again and post the lines from the "Build log".

itbhp

Nothing has changed.  :(

This is the build log.


mingw32-g++.exe -march=pentium-m -Os -W -g    -c "C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.cpp" -o "C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.o"
C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.cpp: In function `int Sum_even(std::vector<int, std::allocator<int> >)':
C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.cpp:24: warning: comparison between signed and unsigned integer expressions
C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.cpp: In function `void stampa(std::vector<int, std::allocator<int> >)':
C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.cpp:30: warning: comparison between signed and unsigned integer expressions
mingw32-g++.exe  -o "C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.exe" "C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.o"   
Process terminated with status 0 (0 minutes, 2 seconds)
0 errors, 2 warnings

Checking for existence: C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.exe
Executing: C:\Programmi\CodeBlocks/cb_console_runner.exe "C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.exe" (in C:\Documents and Settings\paolo\Documenti\My_sources\c++)
Process terminated with status 0 (0 minutes, 11 seconds)

"Anyone who has never made a mistake has never tried anything new."
A.E.

rhf

itbhp,
It looks like it is running.  Are you sure the output window is not closing?
You might try: Project->Properties->Build targets
        and under Type: Console application:  check 'Pause when execution ends'.

itbhp

#6
rhf said
Quote
You might try: Project->Properties->Build targets
        and under Type: Console application:  check 'Pause when execution ends'.

It was already checked.

I tried also to launch the exact command that codeblocks launches when I click the "Run" button, following these steps:

1. Launch Command prompt
2. change directory into "C:\Programmi\CodeBlocks"
3. C:\Programmi\CodeBlocks> cb_console_runner.exe "C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.exe"

The output was the same:

Process returned 0 <0x0> execution time : 0.109 s
Press any key to continue.

Maybe this cb_console_runner doesn't work as it should.
"Anyone who has never made a mistake has never tried anything new."
A.E.

itbhp

#7
I tried to uncheck "Project->Properties->Build targets and under Type: Console application:   'Pause when execution ends'. "

Now project works fine and to see the output of the program I have just to add these lines to my code:


system("PAUSE"); // or cin.get();



By the way simple file that doesn't belong to any project still doesn't run properly.

Thanks for help.
"Anyone who has never made a mistake has never tried anything new."
A.E.

itbhp

#8
News:

After I renamed C:\Programmi\Codeblocks\cb_console_runner.exe in C:\Programmi\Codeblocks\cb_console_runner-old.exe, now also simple cpp file that doesn't belong to any project runs properly.

:o



"Anyone who has never made a mistake has never tried anything new."
A.E.