Question about C

Question about C

Post just about everything that isn't directly related to Spring here!

Moderator: Moderators

Post Reply
manored
Posts: 3179
Joined: 15 Nov 2006, 00:37

Question about C

Post 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?
User avatar
iamacup
Posts: 987
Joined: 26 Jun 2006, 20:43

Post 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 :P

so no, nothing is wrong with your program... in a way :P
User avatar
BlackLiger
Posts: 1371
Joined: 05 Oct 2004, 21:58

Post 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++.
bamb
Posts: 350
Joined: 04 Apr 2006, 14:20

Post by bamb »

perhaps try running it in from dos shell or clicking the program with mouse2 and setting "don't close on exit"?
User avatar
hrmph
Posts: 1054
Joined: 12 May 2005, 20:08

Re: Question about C

Post 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).
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post by rattle »

You can use getch(); instead of calling pause. Was that in stdio too?
YHCIR
Posts: 190
Joined: 12 Aug 2006, 23:06

Post by YHCIR »

rattle wrote:You can use getch(); instead of calling pause. Was that in stdio too?
curses.h
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post 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.
manored
Posts: 3179
Joined: 15 Nov 2006, 00:37

Post by manored »

Thanks for the info people :-) .
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post 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.
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post 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.
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post by rattle »

Well learning C doesn't help much with C++ from my own experience in the end. That was my concern.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post 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++.
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Post 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.
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Post 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++.
manored
Posts: 3179
Joined: 15 Nov 2006, 00:37

Post by manored »

Wouldnt it be nice if someone invented some program capable of making language conversions... :-)
User avatar
Dragon45
Posts: 2883
Joined: 16 Aug 2004, 04:36

Post 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!
User avatar
Ishach
Posts: 1670
Joined: 02 May 2006, 06:44

Post by Ishach »

it comes after B

8)
Post Reply

Return to “Off Topic Discussion”