|
That is the standard disclaimer that casting is an unsafe operation because it bypasses the compilers type checking. In this case it is safe.
Mazdak wrote:
I think I should delete or release this char * from memory in the end? How is that exactly?
No, there is no new memory allocated by this cast so do not try free ore release any...
John
|
|
|
|
|
John M. Drescher wrote:
No, there is no new memory allocated by this cast so do not try free ore release any...
Oh, got it. Thanks for the help
Mazy
"A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope
|
|
|
|
|
Say I create a Menu with 6 choices. How do I get the computer to read the input from the user.
Preferably in C language
|
|
|
|
|
int input;
scanf("%i", &input);
Artificial intelligence is no match for natural
stupidity.
|
|
|
|
|
i have win32 project and i want to add FindWindow call:
HWND hwnd = ::FindWindow(NULL, TEXT("Calculator"));
However, it keeps on giving me link error:
UDP_Multicast_IOCP_CLIENT.obj : error LNK2001: unresolved external symbol __imp__FindWindowA@8
i use headers:
#include "windows.h"
#include "Winuser.h"
i am a novice so execuse me if i ask a stupid question.
thanks
cheers
|
|
|
|
|
link with User32.lib or put this line in your source:
#pragma comment(lib,"user32.lib")
John
|
|
|
|
|
This was it. You are the best.
thanks much,
cheers
|
|
|
|
|
You might check to see if you are linking with user32.lib in your project options.
vglmco wrote:
i ask a stupid question
A stupid question is one that is never asked.....
Artificial intelligence is no match for natural
stupidity.
|
|
|
|
|
That was exactly it. Thanks.
Although when i added this to Visual Studio 6, "project -> settings->link->WS2_32.LIB, user32.lib", it complained that it could not find WS2_32.LIB.?
Thanks,
cheers
|
|
|
|
|
Hmmm... thinking back it seems to me that WS2_32.lib was not a standard library with VS6. You can search your hard drive for it and add it to your library path. If it's not on your drive, you have to download the latest platform SDK from Microsoft.
Artificial intelligence is no match for natural
stupidity.
|
|
|
|
|
WS2_32.lib is, if memory serves, the WinSock 2 library. I have a copy which was part of the Platform SDK, and one from my VC98\Lib folder, so it should be present. Maybe it depends on the edition of VC++6.0 you have.
I do have Visual Studio SP5 installed, but it isn't included in the fileset for that.
Steve S
|
|
|
|
|
I need desperate help in designing a C Program simulating a casio game.
Any help would be greatly appreciated.
Here is the outline.
Objective
To give students practice in writing functions and calling those functions to perform more complex tasks.
The Problem: Casino
You will write a program that simulates a casino for a single player. The user will initially start with $1000. The user will then be able to choose from the following options:
1) Buy chips
2) Sell chips
3) Play Craps
4) Play Arup's Game of Dice
5) Status Report
6) Quit
Your program will execute each choice until the quits. At this point all of their chips automatically get sold back to the casino and a message prints out how much money the user has left (of the $1000) after gambling.
Craps
One of the most "fair" games to play at a casino is Craps. Here is one version of how to play:
1) Roll a pair of fair six-sided dice.
2) If you roll a 7 or 11, you win!
3) If you roll a 2, 3, or 12, you lose.
4) Otherwise, record what you've rolled. Let this sum be k; also known as your point.
5) If you rolled a point, continue rolling the pair of dice until you get either your point (k) or a sum of seven on the two dice.
6) If k comes up first, you win!
7) If 7 comes up first, you lose.
Arup's Game of Dice
Amazingly, this game is even more "fair" than Craps, but the house still has a 50.2% chance of winning, which is why the casino hasn't gone broke yet! Here are the rules:
1) Roll a pair of dice.
2) If you roll a sum of 11 or 12, you win.
3) If you roll a sum of 2, you lose.
4) Otherwise, record what you've rolled. Let this sum be k; also known as your point.
5) Roll one more time. If this roll exceeds your point(k), you win!
6) If this roll is the same as your point(k) or lower, you lose.
Buying Chips
Chips cost $11. Whenever a customer buys chips, he/she must give the banker some money. The banker will always give the user the maximum number of chips they can buy with the money given to them and return the leftover cash. You will write a single function that takes care of this transaction.
Selling Chips
The casino buys chips back at $10 a piece. You will write a single function that takes care of this transaction.
Functions you must write
Though you may write more functions, here are function prototypes for the ones you are required to write:
// Precondition: None.
// Postcondition: Returns the sum of two random dice rolls.
int pairofdice();
// Precondition: None.
// Postcondition: Plays one game of Craps and returns 1 if
// the player won and 0 if they lost.
int craps();
// Precondition: None.
// Postcondition: Plays one game of Arup's game of dice and
// returns 1 if the player won and 0 if they
// lost.
int arupsdice();
// Precondition: cash is the address of the variable
// storing the amount of money the user is
// wants to spend on chips.
// Postcondition: The number of chips purchased is returned
// and the variable storing the amount of
// money the user paid for chips is adjusted
// to equal the change left over after the
// transaction.
int buychips(int *cash);
// Preconditions: numchips > 0.
// Postconditions: Returns the cash obtained for selling
// numchips number of chips.
int sellchips(int numchips);
// Precondition: The first parameter is the number of
// chips the user has, the second is how
// much cash they currently have.
// Postcondition: A report detailing the number of chips
// and the amount of cash the user has is
// printed.
void statusreport(int numchips, int cash);
References
Textbook: Chapters 3 and 4 Notes: Lectures on loops, functions, random
number generator functions
Restrictions
Name the file you create and turn in casino.c. Although you may use other compilers, your program must compile and run using gcc. If you use your olympus account to work on this assignment, please follow the steps shown in class to create, compile, and test your program. Your program should include a header comment with the following information: your name, course number, section number, assignment title, and date. You should also include comments throughout your code, when appropriate. If you have any questions about this, please see a TA.
Input Specification
Assume that the user always enters the proper type of input, but not always appropriate values. Here are some possible errors you need to check for:
1) Do not allow the user to spend more money on chips than they have.
2) Do not allow the user to bet a number of chips they don't have.
3) Do not allow the user to sell a number of chips they don't have.
4) The user must always bet at least one chip for a game, or they can not play the game.
Assume that these specifications will be followed by the user:
1) They will never enter any negative integers.
2) They will never enter any invalid menu choices.
Output Specification
Your output should follow the examples on the following pages.
Deliverables
A single source file named casino.c turned in through WebCT.
Example Output #1
Welcome to the Casino. Here are your choices:
1) Buy chips
2) Sell chips
3) Play Craps
4) Play Arup's Game of Dice
5) Status Report
6) Quit
1
How much cash do you want to spend for chips?
1100
Sorry, you do not have that much money. No chips bought.
Welcome to the Casino. Here are your choices:
1) Buy chips
2) Sell chips
3) Play Craps
4) Play Arup's Game of Dice
5) Status Report
6) Quit
1
How much cash do you want to spend for chips?
500
Welcome to the Casino. Here are your choices:
1) Buy chips
2) Sell chips
3) Play Craps
4) Play Arup's Game of Dice
5) Status Report
6) Quit
5
You currently have $505 left and 45 chips.
Welcome to the Casino. Here are your choices:
1) Buy chips
2) Sell chips
3) Play Craps
4) Play Arup's Game of Dice
5) Status Report
6) Quit
3
How many chips would you like to bet?
0
Sorry, that is not allowed. No game played.
Welcome to the Casino. Here are your choices:
1) Buy chips
2) Sell chips
3) Play Craps
4) Play Arup's Game of Dice
5) Status Report
6) Quit
3
How many chips would you like to bet?
10
Press 'r' and hit enter for your first roll.
r
You rolled a 8.
Press 'r' and hit enter for your next roll.
r
You rolled a 12.
Press 'r' and hit enter for your next roll.
r
You rolled a 6.
Press 'r' and hit enter for your next roll.
r
You rolled a 7.
Sorry, you have lost.
Welcome to the Casino. Here are your choices:
1) Buy chips
2) Sell chips
3) Play Craps
4) Play Arup's Game of Dice
5) Status Report
6) Quit
4
How many chips would you like to bet?
17
Press 'r' and hit enter for your first roll.
r
You rolled a 3.
Press 'r' and hit enter for your next roll.
r
You rolled a 8.
You win!
Welcome to the Casino. Here are your choices:
1) Buy chips
2) Sell chips
3) Play Craps
4) Play Arup's Game of Dice
5) Status Report
6) Quit
6
After selling your chips, you have $1025. Thanks for playing!
Example Output #2
Welcome to the Casino. Here are your choices:
1) Buy chips
2) Sell chips
3) Play Craps
4) Play Arup's Game of Dice
5) Status Report
6) Quit
1
How much cash do you want to spend for chips?
500
Welcome to the Casino. Here are your choices:
1) Buy chips
2) Sell chips
3) Play Craps
4) Play Arup's Game of Dice
5) Status Report
6) Quit
2
How many chips do you want to sell?
46
Sorry, you do not have that many chips. No chips sold.
Welcome to the Casino. Here are your choices:
1) Buy chips
2) Sell chips
3) Play Craps
4) Play Arup's Game of Dice
5) Status Report
6) Quit
4
How many chips would you like to bet?
46
Sorry, you do not have that many chips to bet. No game played.
Welcome to the Casino. Here are your choices:
1) Buy chips
2) Sell chips
3) Play Craps
4) Play Arup's Game of Dice
5) Status Report
6) Quit
4
How many chips would you like to bet?
5
Press 'r' and hit enter for your first roll.
r
You rolled a 11.
You win!
Welcome to the Casino. Here are your choices:
1) Buy chips
2) Sell chips
3) Play Craps
4) Play Arup's Game of Dice
5) Status Report
6) Quit
4
How many chips would you like to bet?
10
Press 'r' and hit enter for your first roll.
r
You rolled a 5.
Press 'r' and hit enter for your first roll.
r
You rolled a 5.
Sorry, you have lost.
Welcome to the Casino. Here are your choices:
1) Buy chips
2) Sell chips
3) Play Craps
4) Play Arup's Game of Dice
5) Status Report
6) Quit
6
After selling your chips, you have $1005. Thanks for playing!
|
|
|
|
|
maravingian wrote:
I need desperate help in designing a C Program simulating a casio game.
Any help would be greatly appreciated.
1. Please be more specific in the type of help you need.
2. A post this size is unlikely to be read.
3. Almost sounds as though you want some else to do your homework for you.
Artificial intelligence is no match for natural
stupidity.
|
|
|
|
|
I agree with all points that the previous reply. This is post is too big. We are not here to do your homework. And we will help with individual questions if you clearly ask them...
John
|
|
|
|
|
I want to create .pdf file and no money to pay fee of PDF SDK.
Could your how to get free PDF sdk.
|
|
|
|
|
|
Hello, there,
I am using Windows xp and in the diaplay properties-> Appearance. I selected "Windows xp style windows and button". I think in the dialog box, the buttons and check box should be in the xp style. But when I use a VC6 to create a dialog box, the buttons and check box inside are still in the classic style. What should I do to make them xp style. Should I change project setting?
Please tell me how to do it.
BTW, I tried to compile the code that I downloaded from Internet, the buttons are in XP style.
Thanks a lot.
Bin
|
|
|
|
|
There are some articles on this subject at codeproject, if the following does not provide enough information, try searching for XP manifest.
Basicaly you need a manifest file or resource, you can find a manifest file at microsoft. A manifest file contains XML code that informs XP to use XP syle buttons, ect., in your app. You would install the file with a name like MyApp.exe.manifest, in the same directory that you store you application (name MyApp.exe). Or you can add the manifest as a resource to you application its' self. To do that you first create a manifest file then add a new resourse type 24 in the resource pane and then import the manifest file as a resourse and give it an ID of 1.
This is what is contained in the manifest file, you can copy the following and paste it into your new manifest file:
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestversion="1.0">
<assemblyidentity
="" version="1.0.0.0" processorarchitecture="X86" name="CompanyName.ProductName.YourApp" type="win32">
<description>Your application description here.
<dependency>
<dependentassembly>
<assemblyidentity
="" type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorarchitecture="X86" publickeytoken="6595b64144ccf1df" language="*">
INTP
|
|
|
|
|
|
Everything I've found to date on Thread classes are way too complex for what I want. I have a basic Thread class:
<br />
class Thread{<br />
public:<br />
Thread( ) ;<br />
virtual ~Thread( ) ;<br />
<br />
static DWORD WINAPI ThreadFunc( LPVOID lpParam ) ;<br />
<br />
void run( ) ;<br />
void end( ) ;<br />
void resume( ) ;<br />
void suspend( ) ;<br />
<br />
private:<br />
DWORD dwThreadId, dwThrdParam ;<br />
HANDLE hThread ;<br />
<br />
char szMsg[80];<br />
};<br />
What I need is something VERY simple that will allow me to easily extend what I already have to allow my Thread class to be inheritable such that two different classes that inherit it have their own specific critical section...
In Java, when I create a class, I can extend/inherit the Thread class. Let's say,
<br />
class Ant extends Thread{ ...<br />
The Ant class will have a 'run' method somewhere in there that will 'replace' (for want of a better term) the Thread class' own run method.
My C++ Thread class:
<br />
DWORD WINAPI Thread::ThreadFunc( LPVOID lpParam ){ <br />
return 0; <br />
}<br />
I have an Ant class. This class should provide an 'updated' ThreadFunc. I also have a World class. This class should provide a completely different 'updated' ThreadFunc.
Let's say I want:
<br />
Ant::ThreadFunc( stuff ){<br />
for( ; ; ){<br />
cout << "Hi" << endl ;<br />
}<br />
}<br />
and:
<br />
World::ThreadFunc( stuff ){<br />
for( ; ; ){<br />
cout << "Ih" << endl ;<br />
}<br />
}<br />
How can I manage this?
In case it helps, or gives you any ideas as to what I've done already, my Thread constructor is pretty much:
<br />
dwThrdParam = 1; <br />
<br />
hThread = CreateThread( <br />
0,
0,
ThreadFunc,
&dwThrdParam,
CREATE_SUSPENDED,
&dwThreadId
) ;<br />
<br />
cout << "Thread " << dwThreadId << " created." << endl ;<br />
<br />
if (hThread == NULL){<br />
wsprintf( szMsg, "CreateThread failed." ); <br />
MessageBox( NULL, szMsg, "main", MB_OK );<br />
}<br />
My project is to do a virtual ant colony, and I stupidly put down on the project spec that I'd have the ants running as seperate threads. Having other stuff running in its own thread could prove useful, but if I don't get the thread class goin properly, I'll just have to toss that part of the project. :/
Anyhoo - Javalike Thread class in C++.
Code would be great.
Or a good resource on how to do it would be cool also.
/* All those who believe in pshycokenesis, raise my hand.
*/
|
|
|
|
|
This is a very long post which is most likely the reason no one has replied. So what is the problem?
Quaoar wrote:
two different classes that inherit it have their own specific critical section
Is this what you want?
Just declare the critical section in the thread and pass a pointer to the object to the thread proc using the LPVOID lpParam paramater. Each object instance will have its own critical section.
John
|
|
|
|
|
A) you should be using _beginthreadex instead of CreateThread.
B) Make ThreadFunc() private
C) Add a public virtual function unsigned ThreadMain()
D) Passing the this pointer as the param. Inside the static thread function you call a virtual "Run" function through the this pointer: (i.e. ((Thread*)this)->ThreadMain();)
E) In the derived class, add a static data member for a critical section.
Make the critical section as small as possible. I question whether you'll actually need one except, perhaps, for collision detection or the like. Don't ignore the InterlockedExchange() and related calls.
Finally, using a thread for each ant is actually quite inefficient, but I'm sure you already know that. On the other hand, it will impress the easily impressionable.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Thanks guys. I'll try both solutions and see which works best for me.
Yes, I will have to look after collision detection - the ants will have to avoid obstacles placed down by the user.
It only struck me after submitting the project spec that threading each ant would be a kinda bad idea. I'll still try it, and include a note in the report if I decide to take the threads out.
As regards impressing the easily impressionable...
The lecturer who's supervising my project, supervised a different project in Java a year or two ago. When the student was presenting his project, he declared that it was portable. The lecturer was impressed, and asked for a demonstration in Linux. Of course, being in Java, the program worked just fine. The lecturer was highly impressed.
Thanks again for your help John, Joe.
/* All those who believe in pshycokenesis, raise my hand.
*/
|
|
|
|
|
How to Create a Button with Tooltip in "win32 application project"?
|
|
|
|
|
I'm using this :
http://www.codeproject.com/buttonctrl/cbuttonst.asp
but if you won't use more features of this class, (I use it for displaying icon buttons) it would give you too much overhead
rrrado
|
|
|
|
|