Alrighty, I borrowed a C programming book from my cousin to help me get into programming, and I downloaded a bloodshed compiler.
Ok, I typed out this simple function:
#include <stdio.h>
main ()
{
printf("hello, world/n");
}
compile it, save it as a C source file on desktop. I click on the desktop icon I just created to get my output, but the window with the output only pops up for like a millisecond! I need to it stay up, so I can move on the more advanced things where I might actually want to LOOK at my output.
Make sense? I know, I'm completely new to this. I hope you can help me.
TOTAL newb
Started by science, May 15 2008 12:27 PM
16 replies to this topic
#1
Posted 15 May 2008 - 12:27 PM
|
|
|
#2
Posted 15 May 2008 - 01:09 PM
try this:
-open a command prompt.
-drag the desktop icon into it.
-hit 'enter'.
-The program will work
It's doing exactly what you want. It's printing "hello, world", then exiting.
Here's a bit of a picture guide of what I described. I used a perl file to do this, btw.


-open a command prompt.
-drag the desktop icon into it.
-hit 'enter'.
-The program will work
It's doing exactly what you want. It's printing "hello, world", then exiting.
Here's a bit of a picture guide of what I described. I used a perl file to do this, btw.


Edited by suicidal pencil, 15 May 2008 - 01:24 PM.
Programming is an art form. Everyone can program, but few can do it right.
#3
Posted 15 May 2008 - 04:40 PM
THANK YOU!
If anyone else would like to share another way, please feel free to do so.
If anyone else would like to share another way, please feel free to do so.
#4
Posted 15 May 2008 - 08:50 PM
A common way is also to "pause" the program right in the end. It can be done in various ways. You can choose to you use the system-command, pause, in Windows, which will do the job for you, or you can wait for user-input in the end.
system("pause");
or
getchar();
These functions shall be thrown in right before the end of the main-function. Note that the first solution using the pause-command only will work on platforms having the pause-command.
system("pause");
or
getchar();
These functions shall be thrown in right before the end of the main-function. Note that the first solution using the pause-command only will work on platforms having the pause-command.
#5
Posted 16 May 2008 - 03:07 AM
science said:
THANK YOU!
your welcome :)
Programming is an art form. Everyone can program, but few can do it right.
#6
Posted 16 May 2008 - 08:47 AM
Or you can read something to a variable:
It will also wait for input without closing the window :) But it all depends on your platform (OS).
char a;
printf("%c",&a);
It will also wait for input without closing the window :) But it all depends on your platform (OS).
#8
Posted 16 May 2008 - 09:12 PM
Personally, I'd never use any of these solutions, except the one provided by suicidal pencil. I prefer to run, and also compile the program, directly from the terminal.
#9
Posted 17 May 2008 - 02:40 PM
[I]#include <stdio.h>
#include <iostream>
using namespace std;
main ()
{
printf("hello, world/n");
cin.get();
}[/I]
This is what I do, to get it to wait for user input, use cin.get();
#10
Posted 17 May 2008 - 03:05 PM
chili5 said:
[I]#include <stdio.h>
#include <iostream>
using namespace std;
main ()
{
printf("hello, world/n");
cin.get();
}[/I]
This is what I do, to get it to wait for user input, use cin.get();
Personally, I dont like mixing languages, especially I/O functions. And further working on this code can cause strange behavior when mixing cin with scanf or cout with printf. But its my subjective opinion :P
#11
Posted 17 May 2008 - 04:05 PM
That's how I learned to do it, theirs probably better ways but I haven't had any problems using that method as of yet.
#12
Posted 19 May 2008 - 12:01 PM
#include <stdio.h>
#include <stdlib.h>
main ()
{
printf("hello, world[B]/n[/B]");
[I]system("pause");[/I]
}
The italic part is what you actually need. Even as your program works well, the conclusion is that it's very short and it's execution can't be seen, or it simply blinks for a milisecond, as you said.
The system("pause"); part simply means a pause in the console. It actually waits for you to tap something on keyboard in order to continue..
P.s. Please note the bolded /n part as you entered it on wrong way.. Those are to different chars, which means /n is not the same as \n.
If I understood correctly, you wanted a new line, and it's correct to use only \n.


Sign In
Create Account

Back to top









