I am trying to get something to print to my screen aftre i type in the source code. Eveytime i compile and run it it just flashes a dos screen real fast and goes away. How can I see what it is printing to the screen. If anyone can help me i would greatly appreciate it.

>If anyone can help me i would greatly appreciate it.
Sure.

How can I see what it is printing to the screen.

try going to your dos window first, navigating to the appropriate directory and then running your .exe. Or open a dos window and type in full name and path of your .exe

I am trying to get something to print to my screen aftre i type in the source code. Eveytime i compile and run it it just flashes a dos screen real fast and goes away. How can I see what it is printing to the screen. If anyone can help me i would greatly appreciate it.

I think you have to add a line of code like

system("pause");

at the point you want to pause the screen.

I tried to open the dos screen first and then type it in and it still says i have have an error in the log or something i just simply want to see what it does when i go to run it. I cannot get it to print to the screen. i am very greatful for your help


try going to your dos window first, navigating to the appropriate directory and then running your .exe. Or open a dos window and type in full name and path of your .exe

I tried to type in the system("pause") and that was not working. My professor said something about a scanf stopping it or something. Do you know what he means by that? Again thank you for your help

I think you have to add a line of code like

system("pause");

at the point you want to pause the screen.

Thank you Dave. I really do appreciate it. This is so stressful and i have no help so your help is greatly appreciated. I have never programed a day in my life and this is the only reference i have. Do you have anymore suggestions for me??

When you follow this link, there is another link on that page:
How do I get my program to wait for a keypress?

So how would I get this to print to my screen without the dos prompt going away really fast? I know i am probably asking stupid questions but I am really trying to understand this

#include <stdio.h>

int main()
{
("Hey,you,I'm alive! Oh, and Hello World!");
}

Thank you Dave. I really do appreciate it. This is so stressful and i have no help so your help is greatly appreciated. I have never programed a day in my life and this is the only reference i have. Do you have anymore suggestions for me??

>So how would I get this to print to my screen without the dos prompt going away really fast?

#include <stdio.h>
 
 int main(void)
 {
 	puts("Hey,you,I'm alive! Oh, and Hello World!");
 	/* insert code to wait for user input */
 	fputs("Press enter to continue...", stdout);
 	getchar();
 	return 0;
 }

There is another way that I do it and I had the same exact problem as you did. You want to use the getch() function. I assume you are not to concerned with the amount of memory it uses its only around 75 k.

#include <conio.h>
#include <stdio.h>
#include <iostream.h>

void main()
{
cout<<"Hey,you,I'm alive! Oh, and Hello World";
getch(); //this terminates the program when you hit enter
}

I have the same exact compiler so if you need any help post a message to me.

>You want to use the getch() function.

There is not much reason to use a nonstandard function when there is a standard one that can do much the same.

Add a line
system("pause");
before you enter
return 0;

commented: Did you read the posts above?? -1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.