go away spammer

Author Topic: Problem in Dev-C++  (Read 3763 times)

0 Members and 1 Guest are viewing this topic.

Offline garriwilsonTopic starter

  • Supreme Robot
  • *****
  • Posts: 345
  • Helpful? 0
Problem in Dev-C++
« on: July 12, 2008, 06:16:04 PM »
I started learning programming, and I downloaded a recommended Dev-C++ compiler and editor.

This is what I put in for Hello World program:

Code: [Select]
#include <stdio.h>

main()
{
      printf("Hello, World!\n");
      return 0;
}

All compiles correctly and then I press Run and it just pops up in the black cmd window for a fraction of a second and disappears. ??? Anybody have this problem how do I fix it?

Then the book has an exercise program so i thought I'd try it and see if that worked:

Code: [Select]
#include <stdio.h>

int x,y;

main()
{
      for ( x = 0; x < 10; x++, printf( "\n" ) )
          for ( y = 0; y < 10; y++ )
              printf( "X" );
             
      return 0;
}

same thing happens... pops up in a cmd window for less than  second, i cant catch if it says what it's supposed to

I couldn't find this anywhere on google

EDIT:
lol i managed to take a screenshot after like 100 tries ::)
but it's too big to attach here :(

thank you
« Last Edit: July 12, 2008, 06:23:05 PM by garriwilson »

Offline Cotowar

  • Full Member
  • ***
  • Posts: 50
  • Helpful? 0
  • Ubuntu for Humans
    • The Tech Stop
Re: Problem in Dev-C++
« Reply #1 on: July 12, 2008, 10:08:20 PM »
if that happens its because the program is running correctly. you started it, but you didnt tell it to wait for you to close it manually, so it just closes itself when its done. Look farther ahead in your book and you'll see something about a pause statement or break or something like that. I cant exactly remember the syntax of it, because i havent used C++ in a long long time, but yea, just look up break statement or pause statement.

That should solve your problem.

Cheers mate.
--Cotowar--

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
    • izua electronics
Re: Problem in Dev-C++
« Reply #2 on: July 13, 2008, 07:48:34 AM »
a common thing to do in windows is to invoke the pause program, by using: system("pause");
i'd recommend you switch to code::blocks. really. it has templates for both PC and microcontroller developement (so you can manage a project on both side from one software), and it adresses this problem of disappearing consoles with custom data about program results.

plus, it's so much better as an editor: code folding, zoom, code completion that works.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline garriwilsonTopic starter

  • Supreme Robot
  • *****
  • Posts: 345
  • Helpful? 0
Re: Problem in Dev-C++
« Reply #3 on: July 13, 2008, 02:56:26 PM »
Thanks, so now I know this isn't an error.

I'll look up the pause command now.

Offline mohamed

  • Full Member
  • ***
  • Posts: 88
  • Helpful? 0
Re: Problem in Dev-C++
« Reply #4 on: July 09, 2009, 03:17:40 AM »
i used the Dev C++ also and about the pause comand u have to include a header file name <conio.h> before the main function and at the end of the main function you type getch(); this means  dont close the window until i type any character so the screen will be open until u press any key

Offline jamort

  • Supreme Robot
  • *****
  • Posts: 375
  • Helpful? 2
Re: Problem in Dev-C++
« Reply #5 on: July 09, 2009, 05:12:27 AM »
Code: [Select]
#include <stdio.h>
#include <iostream>

using namespace std;

int main()
{
      printf("Hello, World!\n");
      cin.get();

}

try that... note iostream is a c++ preprocessor an i think cin.get() is in that preprocessor or maybe std im not to sure though.... this works
the reason it would pop up and exit was because the number returned was o
my english teacher once said, "dont talk about what you dont know in public...."

so I replied the truth, " Exactly why I dont ever talk about English."

Offline sonictj

  • Supreme Robot
  • *****
  • Posts: 416
  • Helpful? 11
    • Tim's Workshop
Re: Problem in Dev-C++
« Reply #6 on: July 09, 2009, 01:17:00 PM »
another way is system("PAUSE") and then return 0;

Code: [Select]
#include <stdio.h>
#include <iostream>

using namespace std;

int main()
{
      printf("Hello, World!\n");

     system("PAUSE");
     return 0 ;
}

system("PAUSE"); causes the command to ask you to press any key to continue.
« Last Edit: July 09, 2009, 01:19:28 PM by sonictj »

Offline Luke

  • Jr. Member
  • **
  • Posts: 7
  • Helpful? 0
Re: Problem in Dev-C++
« Reply #7 on: July 09, 2009, 02:57:21 PM »
Another possibility is to just run your program from a cmd prompt. I'm a *nix guy, but I'm guessing in Windows you can just open up a cmd window, navigate to your program's directory, and execute it.

Offline jamort

  • Supreme Robot
  • *****
  • Posts: 375
  • Helpful? 2
Re: Problem in Dev-C++
« Reply #8 on: July 09, 2009, 06:40:04 PM »
another way is system("PAUSE") and then return 0;

Code: [Select]
#include <stdio.h>
#include <iostream>

using namespace std;

int main()
{
      printf("Hello, World!\n");

     system("PAUSE");
     return 0 ;
}

system("PAUSE"); causes the command to ask you to press any key to continue.
Yeah but most people suggest not to use that because its not mobile.... I admit Ive done a lot of batch file coding in some of my files but should you do it not really BUT there are times that you dont have a choice....
wheres hes using dev c++ he may as well learn c++ too... lots of stuff that c doesnt have classes etc...
my english teacher once said, "dont talk about what you dont know in public...."

so I replied the truth, " Exactly why I dont ever talk about English."

 


Get Your Ad Here

data_list