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:
>>3
That worked, thank you. >>5
What would you suggest I use in windows?
I was thinking of using VISUAL C++ 2010 EXPRESS but it looked to me like it only worked for C++.
>>11
Being able to just click the RUN button and see the results of my endeavours instead of having to type:
win+R,
cmd,
G:\prog\Ch1\,
Project1.exe
seems like a better use of my time.
Name:
n3n7i2011-08-24 23:05
Rather than just double-clicking your compiled exe, you could run it from inside a cmd Prompt...?
Eg C:/Dev-C> myProg.exe
Name:
n3n7i2011-08-24 23:09
=) Make a shortcut to cmd
Properties > -Start in "name_of_this_directory/" (save repeat chdir)
You could try Code::Blocks if you're not willing to use the terminal. (If you are try MinGW.)
It keeps your program's window open after it terminates.
And getchar() is a horrible solution. Like >>11 says a console program is meant to run in a console. Putting a getchar at the end is a pointless hack.
What are we going to do when the OP comes back complaining the getchar method doesn't work sometimes when there's a scanf in his program? I'd rather avoid any discussion of scanf.
Name:
Anonymous2011-08-25 1:33
<Check them doubles
Name:
Anonymous2011-08-25 1:56
>>21
What was that?
You wanted a discussion about scanf?
YOU GOT IT!
But seriously, you got me intrigued. And besides knowing is half the battle as they say... or something.
Anyways, you got me thinking and searching and I'm starting to wonder if I should really try to learn C or just go to C++ because of this quote I found while doing some more searching: Maybe it's time to consider another language. When Kernighan and Ritchie originally developed C in 1978, it was considered functional, but low level. Now, it is the primary alternative to assembly language.[1] [1]: http://www.astahost.com/info.php/Programming-Windows_t17949.html
What do you think?
>>13
In case you don't know already, everyone who has not moved to *nix should have a "terminal here" context menu item.
Name:
Anonymous2011-08-25 3:39
>>26
Well what do you know!
shift+right click
I learn new things on /prog/ everyday!
Still, I still have to type the name of the file when just clicking run would be much much faster.
>>23
Hmmm... I had written a long reply to this, in which I argued C isn't a portable assembler, and contemplated the nature of programming languages and paradigms, but decided not to post it. You're only at hello world level (no offense intended; it's the truth), and this board is overflowing with spammers and shit-posters anyway.
C or just go to C++
There's a pretty distinct divide in opinion amongst programmers on this. (The ones who want to fit in will pick C having never used C++ or even given it a thought.) The best you can do is learn a language you have a reason to learn. That way you'll be able to motivate yourself, whether it be C, C++ or some other.
After that you'll have to be genuinely interested.
Javascript is usually a good first language, because it can be used to extend your browser (which you probably spend a large amount of time at).
scanf
It doesn't mix well with line buffered consoles. A catch-22: you need to already know you're at the end of a line in order to get to it without risk of retrieving the next line.
Also, /prog/ is being surprisingly Windows tolerant. What's up with that?
>>29 You're only at hello world level (no offense intended; it's the truth)
None taken. I actually have some VB background but I didn't bring it up because this is /prog/ and from what I've seen you guys don't seem to like thems kind around here.
I use getch() all the time when I make programs for my coworkers that require them to look at that output and don't want to have to explain to them how to do it from the command prompt.
There is really nothing wrong with it, and in some circumstances it can save you a lot of time.
Name:
Anonymous2011-08-25 21:08
>>1
Found your problem. You need to declare your main function's return type.
Here try this.
#include <stdio.h>
#define ANUS 12
int main(int argc, char *argv[]) {
printf("Hello World!\n");
return(ANUS);
}
That should do the trick.
Name:
Anonymous2011-08-25 21:40
>>38
The arguments and the type for main() wasn't in the book so I didn't put that there.
Mind if I ask why you put those there and why those seem to stop the getchar() thing from pausing the cmd so I can see the result of my code?
>>39
The code posted in >>38 won't be any different than what you did.
Basically when you run a program, like you did, it will open up an instance of the command prompt (if you're on windows), run the code, and then when it's finished it will close that command prompt because there is no need for it to stay open when it's done.
You can get around this one of two ways. Using getchar() will wait for you to enter a character. You're not actually doing anything with that character, you're just exploiting the fact that the program is stalled and you can see what was output.
The second, and better, way to do it is to open your own instance of the command prompt. Navigate to the folder your program is in by entering "cd C:\path of your program\".
Then enter "program.exe" to run that program.
Don't bother hitting compile and run in the second case, just compile.
Name:
Anonymous2011-08-25 23:21
>>40
Why does batch have a function to pause the program till acknowledged but C which is supposed to be OH SO GREAT doesn't?
And it's not the same at all. He removed the "getchar()" and added "int argc, char *argv[]" and that "ANUS" crap".
Anyways, I added the gerchar and when I ran it, it wouldn't stay open. I think it has something to do with "int argc, char *argv[]" but I do not know.
I agree, Javascript is a fantastic first language. Here's a protip though, Javascript is unlike any language you will ever program in. It has functional elements, and a prototype system. It doesn't have block scope, but function scope. There are plenty of things I could go into but this list would get quite long.
Here's my suggestion if you want to learn Javascript. Firstly, get Firefox because it has Firebug. Next, read Eloquent Javascript. Next, read Javascript : The Good Parts by Doug Crockford while watching his videos at YUI Theatre. That should get you going.
Javascript's community is changing and it's quickly becoming one of the best. With the information I just gave you you're well on your way to becoming a good programmer.
Lastly, don't think that Javascript is just a client side scripting language. Frameworks like Node.js are quickly changing that and exploiting Javascript's natural elegance.
Name:
Anonymous2011-08-26 1:00
>>45
Javascript is an awful first language because it's nothing like any language you will ever program in.
The reason C is the best beginner programming language is because it teaches you how to program, plain and simple. It's as close as you can get to pure programming.
Name:
Anonymous2011-08-26 1:05
>>45
Javascript is an awful first language because it's nothing like any language you will ever program in.
The reason Lisp is the best beginner programming language is because it teaches you how to be an autistic neckbeard, plain and simple. It's as close as you can get to pure /prog/.
Name:
Anonymous2011-08-26 1:16
The reason C is the best beginner programming language is because it teaches you how to program, plain and simple. It's as close as you can get to pure programming.
( ≖‿≖)
>>49 it teaches you how to program, plain and simple. It's as close as you can get to pure programming.
What does this even mean?
Name:
Anonymous2011-08-26 1:36
>>46 The reason C is the best beginner programming language is because it teaches you how to program, plain and simple. It's as close as you can get to pure programming.
So basically what I read in >>23
about how C is as close to assembly as you can get, was correct?
>>57
Pureness is a subjective property that someone defines for themselves, hence nobody can be delusional when defining what is essentially their personal opinion about a meaningless word.
>>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:
Anonymous2011-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:
Anonymous2011-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.
>>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.
>>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.
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:
Anonymous2011-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?
>>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.