Page 1 of 1
Question about C
Posted: 18 Jan 2007, 01:20
by manored
#include <stdio.h>
int main()
{
printf("This is output from my first program!\n");
return 0;
}
###
Then I run the sample program above it opens only for a eye blink and then quits. Does that happens because its not programed to wait or it should wait and so the problem is with my compiler?
Posted: 18 Jan 2007, 01:32
by iamacup
run this
Code: Select all
#include <stdio.h>
int main()
{
printf("This is output from my first program!\n");
system("pause");
return 0;
}
what your program sais is
ok
get some headers
start the main bit
print something
return a good old exit code to windows
windows gets this, knows the application has finished, closes it
so no, nothing is wrong with your program... in a way

Posted: 18 Jan 2007, 01:42
by BlackLiger
If you're running it in a visual compiler like Microsoft Visual C, try doing the "Run without debug." option. Thats what works in Visual C++.
Posted: 18 Jan 2007, 02:12
by bamb
perhaps try running it in from dos shell or clicking the program with mouse2 and setting "don't close on exit"?
Re: Question about C
Posted: 18 Jan 2007, 07:48
by hrmph
manored wrote:Does that happens because its not programed to wait
Yes... Try using sleep or something similar (even a getc or scanf).
Posted: 18 Jan 2007, 15:29
by rattle
You can use getch(); instead of calling pause. Was that in stdio too?
Posted: 18 Jan 2007, 16:58
by YHCIR
rattle wrote:You can use getch(); instead of calling pause. Was that in stdio too?
curses.h
Posted: 18 Jan 2007, 17:15
by rattle
lol
Quite frankly start with C++ instead of C and read up on OOP, that's the way to go. Knowing C doesn't really help with C++ a lot. Also if you are interested in AI coding, most of the AIs are in C++.
Your typical hello world
Code: Select all
#inlcude <iostream.h>
void main(int argc, char* args[])
{
cout << "HOLLA WOLRD!" << endl;
cin.get();
}
The same with very basic OOP
Code: Select all
#inlcude <iostream.h>
class CHollaWorld {
CHollaWorld();
~CHollaWorld();
void Spam();
};
void CHollaWorld::Spam() {
cout << "HOLLA WOLRD!" << endl;
cin.get();
}
void main(int argc, char* args[])
{
CHollaWorld HelloWorld;
HelloWorld.Spam();
}
Haven't checked wether it runs or not nor if the syntax is correct though.
Posted: 18 Jan 2007, 17:51
by manored
Thanks for the info people

.
Posted: 18 Jan 2007, 22:40
by AF
Most minor AIs with AI devs learnign to code in C based languages (SAI by spectre, TAI by me) usually do it very badly because they use C style arrays for everything, and have no thoughts about proper object orientated modularity with usage of containers and other STL niceties.
This usually means the AI has a short lifespajn as it isnt flexible enough to expand and become more advanced and mature. AI needs modularity in the extremes. They need to be highly extendable in their design.
Posted: 18 Jan 2007, 22:49
by jcnossen
C++ contains a lot more "magic" stuff though, such as the << operators that look like inconsistent syntax to newbies I think.
And a beginner making an AI in C++ will make it just as inflexible as in C (although slightly fewer memory bugs maybe..), so I doubt thats a real difference.
Posted: 18 Jan 2007, 23:58
by rattle
Well learning C doesn't help much with C++ from my own experience in the end. That was my concern.
Posted: 19 Jan 2007, 00:00
by AF
I believe it makes the whole learning process quicker with regards to AIs. I know my progress started to quicken once I stopped using old C stuff and moved to STL stuff and other marvels of C++.
Posted: 20 Jan 2007, 15:13
by PauloMorfeo
That program runs in a console. Windows opens a console for that program and, when finished, closes it.
If you run that program from a console open by yourself it will only be closed when you order it to.
Posted: 20 Jan 2007, 15:16
by PauloMorfeo
Ho, and C and C++ suck tremendously as languages (and even as learning platforms), now that i have seen the light after so many years strugling with all the shit that comes with the ill-fated mix that is C/C++.
Posted: 23 Jan 2007, 04:07
by manored
Wouldnt it be nice if someone invented some program capable of making language conversions...

Posted: 23 Jan 2007, 08:04
by Dragon45
I can't believe its not obvious that <my language(s) of choice> are clearly superior! For example, <my language(s) of choice> has the following:
1) Ease of use
2) <More stuff>
3) Plus, there's <some random number of applications> well-known applications coded in it!
<Conspicuous ignoring/shrugging off of bad points concerning language>
Clearly, it is superior!
Posted: 23 Jan 2007, 10:39
by Ishach
it comes after B
