Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Learning C through K&R book

Name: Anonymous 2011-08-24 21:12

I already compiled and ran my first code but there's this thing.
When I run it, cmd flashes and disapears.(I'm using Dev-C++ on windows to make it)
Anyways, I think there was a command or function to make the cmd pause till I press enter or something like that so that I am able to read whatever the output was, the thing is, I cant remember the name of the function or how to write it.
Can one of you tell me which it is, if there is one.
BTW here's my code:


#include <stdio.h>

main ()
{
  printf("Hello World!");
}

Name: Anonymous 2011-08-31 8:17

>>74
actually EOF is ctrl+Z

Name: Anonymous 2011-08-31 14:56

>>81
That is system dependent.

Name: Anonymous 2011-08-31 15:37

>>39
You should always declare the type of your main(). Int is usually enough, as your main() returns the run code (in most cases 0, when program has terminated succesfully). The arguments are for arguments passed from command prompt / terminal - as in, when you execute the program from command prompt like >>40 said, you can add arguments. Example: path\> program.exe arg1 arg2 arg3 etc. Those arguments are then saved in the variable argv[], which is an array of strings (arguments you wrote on the prompt). The first argument (index 0, you'll learn about that when you read about arrays) is always the program's name (program.exe in our case) and the rest are arguments you passed. Argc stands for argcount, aka number of arguments passed to the program. It always equals to at least 1 (remember? The element 0 of array argv is program name), so you can easily check if user specified required amount of options / files.

About return(), you should always add return(0); (or return 0;) to the end of your main. If you use gcc with -Wall flag, you'll get a warning if you don't do this. I recommend setting -Wall and -pedantic flags if you use gcc in your compiler options. (Tools > Compiler Options > tick Add the follwing commands when calling compiler > write -Wall -pedantic > OK in Dev-C++). Though I recommend Code::Blocks if you want to code in C on Windows.

Name: Anonymous 2011-08-31 15:59

About return(), you should always add return(0); (or return 0;) to the end of your main.

Not always. If the OP does any kind of non-trivial C program in the *nix environment, having the program return(0) may not actually terminate the process. That said, I would just follow what the various C standards say and use

exit(EXIT_SUCCESS);

instead of

return 0;

That way, you could be sure the program would behave as expected across various platforms.

Name: Anonymous 2011-08-31 16:02

>>75
That program is supposed to read from a file, not your keyboard. try ./out < infile -- it should cat the file to stdout.

No. The program reads from the standard input. This may be connected file. But it could also be connected to a keyboard. You still suck. Go serve another customer you mental midget.

Name: Anonymous 2011-08-31 16:04

>>80-84
all wrong

Name: Anonymous 2011-08-31 16:09

>>86
I'm wrote number 84. The reason why I say what I said was because we had a bug at that stemmed from the programmer using return 0. But you wouldn't be aware of something like this because you don't have the mental capacity to do any kind of real programming work for a major US firm. Now shut up and go clean another toilet you mental midget.

Name: Anonymous 2011-08-31 16:09

er *had a bug at work*

Name: Anonymous 2011-08-31 16:27

>>87
LOL

Name: Anonymous 2011-08-31 16:35

>>89
Oh aren't we cool. We can LOL on dat der intranet. I'm don't interview idiots that use internet slang. No shut up, reread what I just wrote and try to learn something you fucking nigger.

Name: Anonymous 2011-08-31 16:42

I think obnoxious kodak programmer is actually a bot.

Name: Anonymous 2011-08-31 16:43

>>90
Then who was phone?

Name: Anonymous 2011-08-31 21:01

>>82
On any REAL OS it is Ctrl+D.

Name: Anonymous 2011-08-31 21:05

right before the end, you need:

system("PAUSE");
return 0;
}

system pause tells your compiler to leave the dos window on screen.

Name: Anonymous 2011-09-01 22:16

>>94
THANK YOU!!!
That's what I wanted.

Though, for some reason it doesn't "run" when I click the "compile & run" button if I comment out this line:
#  getchar(); #pauses and waits for a key input


>>83
>>84
Thank you both for taking time to explain these things.

Name: Anonymous 2011-09-01 22:26

I'm a computer science major at San Francisco State University that has to take a semester of set theory. I think this is the departments effort to "enlighten the undergrads."

Now, we just finished the second week, and half the class has is already lost. Why is this?

Name: Anonymous 2011-09-01 22:30

The course is CSC 230

Name: Anonymous 2011-09-02 13:16


━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
                                             ┃
                                             ┃
                                             ┃
                                             ┃
                                             ┃
                                             ┃
          ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛            
          ┃
          ┃
          ┃
          ┃
┏━━━━━━━━━┛



Name: Anonymous 2011-09-02 13:17

◀━━━━━━━━ CHECK THEM DUBZ

Name: Anonymous 2011-09-02 15:27

>>96
Now, we just finished the second week, and half the class has is already lost. Why is this?
Because you're attending a shit educational facility where your fellow students are fucking retards, computer science students usually are which is why at every programming competition they get severely outperformed by students who study something which requires intelligence like mathematics.

Name: Anonymous 2011-09-02 15:31

>>96
BULLSHIT
San Francisco is not a state

Name: Anonymous 2011-09-02 17:40

>>100
Anyone who doesn't understand Mathematics is lost in a sea of dicks

Name: Anonymous 2011-09-02 18:01

San Francisco LOL gay

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List