William Hemsworth 1,339 Posting Virtuoso

Would you mind posting the entire project zipped (with unneeded compiler generated files excluded) so I can run it and take a closer look.

William Hemsworth 1,339 Posting Virtuoso

I drew it out on mspaint first, and managed it.

Sulley's Boo commented: *claps* +6
William Hemsworth 1,339 Posting Virtuoso

It didn't really annoy me at all, especially when you realize that originally that post boosted my rep by 42 points, and thanks to serkan that dropped to 40... :(

Thanks tux, but remember not to take it too seriously, especially when it's not your own rep.

Nick Evan commented: *nods* +18
William Hemsworth 1,339 Posting Virtuoso
RECT r;
GetWindowRect( hwnd, &r);
ClipCursor( &r );

Replace hwnd with whatever the window is called, and you're done.

Emin_3 commented: Thanks. It works.. +0
William Hemsworth 1,339 Posting Virtuoso

>Use some graphics library.
There's not much point in recommending that, we first need to know some details before simply telling him to use a graphics library. If he's using the Win32 API, he can simply use CreateFont and use the returned object with the window HDC.

If he plans on doing this with a console window, then there's problems.

William Hemsworth 1,339 Posting Virtuoso

Depends, if you mean using the Win32 API, then it's easily possible. AFAIK it's not possible to set the font size on the console through just using C++ code.

William Hemsworth 1,339 Posting Virtuoso

>i wasnt going to say anything as i promised, but Narue triggered it
How did post #5 trigger you?

>because of Narue i am not going to make any good reputation in this website
Don't blame her, it's you who keeps making it worse for yourself.

>couple of people including you, are interested in my reputation points still
As far as I know I am using the rep system correctly. However when you say something such as "why didnt you say anything about my code snippet?" which is clearly trying to attract more attention to the subject, that makes me annoyed.

This is another thread which is going downhill, and will probably be closed soon enough.

tux4life commented: Well said! +8
William Hemsworth 1,339 Posting Virtuoso

just because of Narue i am not going to make any good reputation in this website, who cares, i will always love her nomatter what. i was going to marry her if i could.

In that case, stop complaining about your reputation and simply do as sknake just said. Although it's not really supposed to matter, reputation is there to show what people really think of you, and recently I'm not surprised that opinion has dropped.

Remember what you said, you should try referring to it more often.

i promise here, with my own words, from now on, Narue is just another poster for me, i am not going to mention her

William Hemsworth 1,339 Posting Virtuoso

>They work by using if/or commands
So does every program ever created.

>chooses the best thing to say based on what the user asked/said
It sounds easy when you say it like that, but associating subjects with each other isn't all that simple.

William Hemsworth 1,339 Posting Virtuoso

It's a great film with a great twist, here's the trailer.

William Hemsworth 1,339 Posting Virtuoso

"Fear can hold you prisoner. Hope can set you free."

- Tagline from the Shawshank Redemption.

William Hemsworth 1,339 Posting Virtuoso

Some of my favourites:
- The Shawshank redemption
- Untraceable
- The new Star Trek

William Hemsworth 1,339 Posting Virtuoso

Pretty much all of your threads have had something to do with finding the CPU usage in different operating systems. I think you should find some multi-platform library to do this for you instead of figuring each one out yourself.

William Hemsworth 1,339 Posting Virtuoso

>If it's a class object (see OP), memmove can't move elements correctly!
What do you mean? All memmove does is move memory. So even if you want to use your own class object, it should still work.

#include <iostream>
using namespace std;

struct mystruct {
  char text[5];
};

template<typename type>
void removeElement(type a[], int size, int index) {
  memmove(
    &a[index],                      // Dest
    &a[index + 1],                  // Source
    (size - index) * sizeof(type)   // Size
  );
}

int main() {
  mystruct a[5] = {"a","b","c","d","e"};
  int elementCount = 5;
  int removeIndex = 2;

  removeElement( a, elementCount, removeIndex );
  --elementCount; // Short array length

  for (int i = 0; i < elementCount; ++i)
    cout << a[i].text;
}

>remove class object means call destructor...
I know, but that's why I asked if there was any real need to destruct the element, when you can just you can simply ignore it and shift array elements around without the need of having to free any memory until the very last moment.

Though as you said, I agree that the OP should stick to SDL containers for the reasons you have suggested.

William Hemsworth 1,339 Posting Virtuoso

I don't see much need in actually deleting the one element by itself. If you don't need that element, simply ignore it until it's time to completely destruct the array.

If you want to remove an item in the middle of the array, it's easiest to use ArkM's suggestion and use STL containers, but it's a simple task either way. Simply shift each element after the deleted index left by one place, like this:

#include <iostream>
using namespace std;

void removeElement(int nums[], int size, int index) {
  memmove(
    &nums[index],                  // Dest
    &nums[index + 1],              // Source
    (size - index) * sizeof(int)   // Size
  );
}

int main() {
  int nums[5] = {1,2,3,4,5};
  int numCount = 5;
  int removeIndex = 2;

  removeElement( nums, numCount, removeIndex );
  --numCount; // Shorten array length

  for (int i = 0; i < numCount; ++i)
    cout << nums[i];
}

This outputs:

1245

William Hemsworth 1,339 Posting Virtuoso

Would you mind sharing reason for using { } so frequently ?

Most probably used most when programming, though really the most used key for everybody should be the space bar or one of the more common keys.

William Hemsworth 1,339 Posting Virtuoso

The internet.

William Hemsworth 1,339 Posting Virtuoso

Creating a vector of char* is a dangerous thing to do, as if a pointer to a string was added to the vector in a different scope, the data that the pointer is pointing to may not be valid anymore. For example, the following will work:

vector< char* > myVector;
vector< char* > ::iterator myIterator;

char temp[2] = "t";
myVector.push_back( temp );

myIterator = myVector.begin();
cout << *myIterator << endl;

However, this may not:

vector< char* > myVector;
vector< char* > ::iterator myIterator;

// Some condition
if ( true ) {

  char temp[2] = "t";
  myVector.push_back( temp );

}

myIterator = myVector.begin();
cout << *myIterator << endl;

To be safe, it's easiest to simply create a small structure and remove that risk altogether.

struct mystruct {
  char temp[2];
};

int main() {
  vector<mystruct> myVector;
  vector<mystruct> ::iterator myIterator;

  mystruct temp = {"t"};
  myVector.push_back( temp );

  myIterator = myVector.begin();
  cout << (*myIterator).temp << endl;
}

Hope this helps.

Salem commented: Nice post +33
tux4life commented: Good post ! +8
serkan sendur commented: good post -1
William Hemsworth 1,339 Posting Virtuoso

I got it working by using:

int c_gen = rand()%3+1;
OB *ob1;
ob1 = new OB[c_gen];

Thanks again!

Okay, but now you have to be cautious of memory leaks, when you have finished doing stuff with ob1, you MUST free that memory using the delete oeprator, like this:

delete[] ob1;

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

That's because you can not set the size of an array at runtime. If you want do this, research dynamic allocations using the new keyword.

William Hemsworth 1,339 Posting Virtuoso

It's a dangerous thing to do, but:

double *a = (double*)0x245CEA20;
std::cout << (*a);
William Hemsworth 1,339 Posting Virtuoso

Not only that but I will show you mathmatical properties of some parts of the english translated (aramaic) new testament that are so precise that they are outside of the ability of a normal human with a computer to concieve.

I'm looking forward to that day...

William Hemsworth 1,339 Posting Virtuoso

Do what you like the most, though if it were me I would start off with something lower level like C/C++ as it will give you a better understanding of computers in general. If you then want to move into a faster method of programming, learn something such as C# or C++ .NET.

William Hemsworth 1,339 Posting Virtuoso

Control a PC from a cell phone? I highly doubt that's something you could manage even with the help here. The only way I can think of doing that is sending emails from your phone, having a program on your PC to recieve them and follow instructions. Even if you somehow managed to get some communication between the two, I don't see how much help you could be to your parents with what little control you will have over your PC.

William Hemsworth 1,339 Posting Virtuoso

Too slow? I just made a program which loads 60000 words, and it managed that in about a 1/10th of a second. Use simple file streams (std::ifstream) and vectors, and speed shouldn't be a problem.

William Hemsworth 1,339 Posting Virtuoso

>water
Actually, it was a secret.

William Hemsworth 1,339 Posting Virtuoso

A1: A towel?
A3: A mole?

Two random guesses.


If you have me, you want to share me. If you share me, you haven't got me. What am I?

William Hemsworth 1,339 Posting Virtuoso

My most blurred key is the Caps-Lock, probably caused by a thick layer of dust that's built up over the years :P My most used key (and cleanest) is probably the space bar, seems logical as you use it at the end of almost every word.

William Hemsworth 1,339 Posting Virtuoso

C++ is case sensitive, so class c : public A,b should be class C : public A, B

William Hemsworth 1,339 Posting Virtuoso

I think it just combines the use of a large database while perhaps using some fuzzy logic and 'clever' algorithms. As the database gets larger, it has more information to interpret and make associations with, making it seem more realistic I guess. [link]

William Hemsworth 1,339 Posting Virtuoso

I'm pretty sure:

lulz--That's not even a question, how dare you waste the great Oracle's time!

was iamthwee too :D

William Hemsworth 1,339 Posting Virtuoso

>When were you born?--I'm an Oracle not a time traveler!
That would have been me.

William Hemsworth 1,339 Posting Virtuoso

>No, YOU write it!
Don't get carried away. I think he was just quoting his question, after all, he did say "Im not here for the codes but rather someone could spur me up so that i can kickstart."

>thrown 3 qns
I guess that means questions, use good English please.

>i need someone to recommend me good sources for beginners for File I/O, ADTs and Dynamic Structures
[link] [link] [link] and [link]

>ive got no clue how to start
Always start with something, no matter how small.

#include <iostream>
using namespace std;

int main()
{
  // You have a starting point.
}

Hope this helps.

csurfer commented: Cool use of intellect buddy...!!! :) +1
tux4life commented: Solid post! +8
William Hemsworth 1,339 Posting Virtuoso

So, are you trying to make the puk bounce when it hits the top or the bottom? If so, simply invert the Y-Velocity like this:

if ( box.y < 0 ) {
  yVel *= -1;
  box.y = 0;
}

else if ( box.y > curLvlHeight - PUK_HEIGHT ) {
  yVel *= -1;
  box.y = curLvlHeight - PUK_HEIGHT;
}

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

Sorry, fixed quite a bad bug.

William Hemsworth 1,339 Posting Virtuoso

They're pretty easy to make, I made one a long time ago that I called "The Oracle". I didn't add as many edge cases and it didn't use a database but it was fun nonetheless

Heh, not bad. I did notice how it seems to deny most questions or try work itself around the question instead of actually answering it, but it's fun :D

William Hemsworth 1,339 Posting Virtuoso

I made a small program which if you add to startup, should do what you want. To close the program, press and hold each key (in the right order) C - L - O - S - E

I hope this helps.

William Hemsworth 1,339 Posting Virtuoso

I'm not sure if this is possible with Vista, there's probably already software available on the internet to do this, but if you planned on doing it manually, you need these 3 main things:

  • To be able to disable all system hotkeys, so the internet explorer can't be closed.
  • Make the window fullscreen, so the taskbar isn't visible.
  • Make the program run on startup.

In programming, the first two points could be quite easily achieved. As for the third point, you just need to add the program to the 'Startup' folder.

William Hemsworth 1,339 Posting Virtuoso

In short I guess it just includes more code in the actual executable file instead of relying on other dll's which your brother doesn't seem to have on his PC. I always compile on /MT as it just increases the portability of the program for a small sacrifice of about 100kb.

William Hemsworth 1,339 Posting Virtuoso

Nah! keep them, I found this thread amusing :D

William Hemsworth 1,339 Posting Virtuoso

if ( color && 1 ) puts("violet");
if ( color && 2 ) puts("indigo");
if ( color && 4 ) puts("blue");
if ( color && 8 ) puts("green");
if ( color && 16 ) puts("yellow");
if ( color && 32 ) puts("orange");
if ( color && 64 ) puts("red");

Shouldn't it be a & and not a &&? Otherwise the && # is pointless.

jephthah commented: yes, your're right. and this is embarrassing. :P +10
William Hemsworth 1,339 Posting Virtuoso

>William, regarding your post (#11): I think that int main( void ) is the preferred way in C
I think we're looking into things far too much here. It works now, so let's just leave it at that, OK? :icon_wink:

I'll start using a void parameter from now on.

tux4life commented: There's a difference :P +7
William Hemsworth 1,339 Posting Virtuoso

Arw: Click Here

>SORRY AGAIN!
Stop posting code to a solved thread (without code-tags), and you wont need to say sorry.

William Hemsworth 1,339 Posting Virtuoso

It is always better to put the statements in if conditions in brackets. And start using else if's.

Who says using brackets is better? IMO your code was harder to read than the original code. If it were me, I would have written it like this:

#include <stdio.h>

int main() {
  int color;
  
  printf( "Enter any number:\n> " );
  scanf( "%d", &color );

  switch ( color ) {
    case 1:  printf( "\nviolet" );  break;
    case 2:  printf( "\nindigo" );  break;
    case 4:  printf( "\nblue" );    break;
    case 8:  printf( "\ngreen" );   break;
    case 16: printf( "\nyellow" );  break;
    case 32: printf( "\norange" );  break;
    case 64: printf( "\nred" );     break;
  }

  getchar();
  getchar();
}
iamthwee commented: Sorry but I disagree with your brackets statement! -4
Aia commented: If you disagree make a relevant post about it. Instead of grading posts like if you were somebody. +17
William Hemsworth 1,339 Posting Virtuoso

If you're using VS, try changing the runtime library to what is shown in my screenshot, while making sure the mode is set to release.

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

>>...but #include "stdafx.h" is missing
>Please note that it's not needed for non-Microsoft compilers
It's not needed for Microsoft compilers either. :icon_rolleyes: I hate how they use that as a default include for generated code. That's one of the reasons I always create an empty project with Visual Studio instead of using the templates.

I do the same thing, I only ever use stdafx.h when including large header files to minimize build time, like when I had a generated header file with about 60000 constant c-strings in it (I was making a scrabble solver and didn't want any loose files :P).

William Hemsworth 1,339 Posting Virtuoso

>A Lot people says that Windows XP is much better than VISTA? why?
No, it's not true. Many peoples opinion is that XP is better and more reliable than Vista, but I disagree.

>the files you created in Windows XP could not be opened if you use VISTA Operating System? is it true?
Almost all programs that run on Vista run on XP as well, and considering it's mostly to do with the software that writes and reads to files, I don't see how this has anything to do with the OS.

William Hemsworth 1,339 Posting Virtuoso

Good grief! initialize the array like this: int sudoku[9][9] = {0};

That's not what I meant :P
He could replace some of the 0s with numbers of his choice, instead of entering them in one by one on each line.

William Hemsworth 1,339 Posting Virtuoso

This code is unintelligible.

I can't quite tell with the current formatting, but is that supposed to be an 8 - levelled for loop? Rewrite your code, using int main( void ) instead of void main() , and make sure it has a decent structure.

Initialize your sudoku like this:

int sudoku[9][9] = {
  {0,0,0, 0,0,0, 0,0,0},
  {0,0,0, 0,0,0, 0,0,0},
  {0,0,0, 0,0,0, 0,0,0},

  {0,0,0, 0,0,0, 0,0,0},
  {0,0,0, 0,0,0, 0,0,0},
  {0,0,0, 0,0,0, 0,0,0},

  {0,0,0, 0,0,0, 0,0,0},
  {0,0,0, 0,0,0, 0,0,0},
  {0,0,0, 0,0,0, 0,0,0}
};

Do that, then I will help more.

William Hemsworth 1,339 Posting Virtuoso

If you want to compare the probability of whatever it is, you shouldn't use the == operator, instead do...

if ( fabs(prob) - 0.5 < 0.001 ) {
  counter++;
}

You can change 0.001 to a precision of your choice.