William Hemsworth 1,339 Posting Virtuoso

Rage Against the Machine - Renagades of Funk

Ezzaral commented: Good song +21
William Hemsworth 1,339 Posting Virtuoso

This thread is out of control.

To the OP: C++ was designed to allow the programmer to have nearly full control over what's happening in the program. Automatically assigning a pointer to NULL once it's been deleted is a waste of cpu, as once deleted, it's usually not used again until it's been reassigned.

Besides causing many other problems, here is an obvious reason not to.

char *buffer = new char[100];
delete[] buffer;
buffer = new char[50];

Would turn to:

char *buffer = new char[100];
delete[] buffer;
[B]buffer = NULL;[/B] // What's the point in this line
buffer = new char[50];

Or say that you have two dynamic objects which have both been deleted, but you still want to compare the original address to see if they were the same object. You would be unable to do so as all deleted objects point to NULL instead of their original adresses. The point is, the address can still be considered useful even after the data has been freed.

To siddhant3s: There's a difference bettween being rude and helpful. The OP asked a simple question which he learned from, so would it hurt to just be nice? :icon_rolleyes:

William Hemsworth 1,339 Posting Virtuoso

Is it not possible to just close the other one as well?

System::Void exitToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
  // Exit both windows
  [B]myForm1->Close();[/B]
  this->Close();
}
William Hemsworth 1,339 Posting Virtuoso

WH: What are your system specs and compiler?

I use VS2005 professional. 2gb ram, running 32-bit Windows Vista.

William Hemsworth 1,339 Posting Virtuoso

WH: You're saying that the code below does not crash on your system?

#include <iostream>
int main() {
    int matrix[512][512][512];
    matrix[0][0][0] = 1;
    std::cout << matrix[0][0][0] << '\n';
}

Assuming 32-bit ints, that's half a gigabyte! Removing the 3rd dimension works for me, but that's only a megabyte.

Works flawlessly :)

Salem commented: Beware the optimiser reducing the simple program to std::cout << 1 << '\n'; +29
William Hemsworth 1,339 Posting Virtuoso

Both compiled fine for me, in fact, even int matrix[512][512][512]; compiled and ran fine for me.

William Hemsworth 1,339 Posting Virtuoso

>you see, words have meaning. they're funny like that.
Haha :icon_razz: I found that post hilarious.

William Hemsworth 1,339 Posting Virtuoso

>I have got to say this .NET stuff is very frustrating.
.NET is very simple compared to the amount of work needed to accomplish the same task in MFC or plain Win32 API.

Post some code and the errors you are getting.

William Hemsworth 1,339 Posting Virtuoso

It's not surprising your program crashes, it's the same as making an array with a size of: 512 * 512 = 262144 elements, or 1048576 bytes. As Ancient Dragon said, you don't have enough stack space.

>Do you think I would have the same problem if I use a vector instead?
A vector allocates dynamic memory, so it will only work if you have enough free dynamic memory - which it should have.

>Do you know how to overcome this problem?
If dynamic memory doesn't work, which I think it will, there's probably another way to approach the problem without having to allocate so much space.

William Hemsworth 1,339 Posting Virtuoso

Yep, you did :-(

William Hemsworth 1,339 Posting Virtuoso

>how do you manage to make all your threads so creepy
So true :icon_rolleyes:

Serkan, seek help to get over your Narue obsession. :icon_cheesygrin: or just keep it to yourself.

William Hemsworth 1,339 Posting Virtuoso

Wow, that's a big prime :)

It took my computer a few minutes to generate a 13/14 diget prime with a program I made, i'm curious how they discovered such a massive one.

William Hemsworth 1,339 Posting Virtuoso

First of all, the order in which you execute your statements are wrong.

return 0;
system("PAUSE");

That second line is never executed as the main function returns before it has a chance to.

Secondly, you shouldn't be using system("PAUSE") in the first place, use cin.get() . But as the input stream still has characters in it, you will have to call it twice to freeze the program before it closes, like this:

cin.get();
cin.get();
return 0;

Then you also have a whole block of code in the wrong place I think, all this can be moved inside the first if code block.

else if ( choice == '2' ) {

  cout<<"what would you like from the submenu?";

  if ( is_submenu(choice) )
  {
    if ( choice == 'x' )
    {
      cout << "Hello"; //does something
    }
    else if ( choice == 'y' )
    {
      cout << "what"; //does something
    }
  }
}

And you have to let the user input the choice variable again.

Here is the corrected code:

#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

struct node{
  int value;
  node *curr; 
};

bool is_valid (char& s)
{
  return s == '1' || s == '2';
}

bool is_submenu(char& m)
{
  return m == 'x' || m == 'y';
}


int main()
{
  char choice;
  cout << "enter your choice\n";
  cin >> choice;

  if ( is_valid(choice) )
  {
    if ( choice == '1' )
    {
      node *ptr = new node();
      node *ptr2;
      ptr2 …
jephthah commented: i remember when you joined, shortly after me... your posts are always solid. good stuff +8
William Hemsworth 1,339 Posting Virtuoso

>Just wanted to ask how will it know where to output the text?
If you want to output it to your richTextBox1, simply do this:

richTextBox1->Text = IO::File::ReadAllText( openFile->FileName );

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

That's a nice find, Thanks for the link also :)

William Hemsworth 1,339 Posting Virtuoso
openFileDialog1->FileName

This isn't the file contents, it's the file path. Try something like this.

IO::File::ReadAllText( openFile->FileName )

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

Trust me, the program I have in my compiler right now. Is correct

Trust me, it's not. Otherwise it would be working.

Post your revised code so we can see what's wrong.

William Hemsworth 1,339 Posting Virtuoso

>sorry i'm not very good in english
Don't worry about it :)

And as for your question, it depends entirely on what the problem is.

>how can i write the right solution to it ?
Understand what's causing the problem, and think of a way to fix it.
Use the internet to help you.

William Hemsworth 1,339 Posting Virtuoso

I'm surprised it even compiles.

void is_valid (char& s)
{
    return s=='1' || s=='2';
}

void is_submenu(char& m)
{
   return m=='x' || m=='y';
}

Both these functions should be returning bool , not void and there isn't really any need to reference the parameters either.

William Hemsworth 1,339 Posting Virtuoso

>i have a problem in programming
Pretty much every thread in this forum is based on a 'problem in programming', try to be more descriptive next time you make a new thread.

>how can i know the right logical solutions for the problem after reading it ??
That didn't make much sense to me. Is there a specific problem you're having, or is it just a really vague question? If there's an actual problem, post code and give more information.

William Hemsworth 1,339 Posting Virtuoso

I have no idea what's causing that error, the button event compiled and ran fine for me.
The only thing I can suggest is, try removing line 84 and see if it works.

William Hemsworth 1,339 Posting Virtuoso

Attach or post the whole code please? It will be faster than figuring this out with small snippets of your code.

William Hemsworth 1,339 Posting Virtuoso

The Shins - Pink Bullets :]

William Hemsworth 1,339 Posting Virtuoso

> Could you please explain this part of the code as it is giving me errors:

Don't just copy and paste what I wrote, use your head :) Change the name list to what ever you called your listbox. But I just re-read your question, and realized that's not what you want. But adding the entire contents of a file to one line in a list box doesn't seem logical, but if that's what you need, learn how to open a file and read the data.

Hope this helps.

tux4life commented: Well said :) +2
William Hemsworth 1,339 Posting Virtuoso

Well there's your problem, read a tutorial on structures and data types
and you'll find out what you've done wrong. [Link]

William Hemsworth 1,339 Posting Virtuoso

I haven't done Windows Forms for one or two years, but with the help of google... I managed to make this small example for you.

System::Void button_Click(System::Object^  sender, System::EventArgs^  e) {
  OpenFileDialog ^openFile = gcnew OpenFileDialog();

  if ( openFile->ShowDialog() == Windows::Forms::DialogResult::OK ) {
    list->Items->Add( openFile->FileName );
  }

}

Search better next time.

rEhSi_123 commented: Very Helpful +1
William Hemsworth 1,339 Posting Virtuoso

You should be more specific, what do you want your program to do? If it's to create a graph, your best bet would be to use a bitmap library. Here's a snippet I changed slightly so that you at least have a base to draw onto a bitmap. Actually drawing the graph is up to you, I'm just providing a base.

#include <windows.h>
#include <iostream>
#include <cmath>

typedef unsigned long ulong;
typedef unsigned short ushort;
typedef unsigned char ubyte;

struct Pixel {
   union {
      ulong rgb;
      struct {
         // r, g, b share same memory as rgb
         unsigned char b, g, r;
      };
   };

   Pixel() {
      // Automatically set pixel black
      rgb = 0;
   }

   // Init pixel
   Pixel(byte _r, byte _g, byte _b) {
      r = _r;
      g = _g;
      b = _b;
   }

   inline operator ulong() {
      return rgb;
   }

   // Set pixel
   inline Pixel &operator =(ulong _RGB) {
      rgb = _RGB;
      return *this;
   }
};

template<short _Width, short _Height>
struct Bitmap {
   // Pixels
   Pixel *pixels;

   // Dimensions
   short width;
   short height;

   // Init
   Bitmap() {
      width = _Width;
      height = _Height;

      // Allocate Pixels
      pixels = new Pixel[width * height];
   }

   // Destroy
   ~Bitmap() {
      // Free all pixels
      delete[] pixels;
   }

   inline Pixel &operator()(short x, short y) {
      // Returns reference to pixel
      return pixels[(height - ++y) * width + x];
   }

   void save(const char *_FileName) {
      // Function to save as bitmap (no compression)
      BITMAPINFOHEADER bmpInfoHeader = {0};

      // Properties
      bmpInfoHeader.biSize = sizeof(BITMAPINFOHEADER); …
William Hemsworth 1,339 Posting Virtuoso

hey guys, emm can someone explain fast for me how to get to the programming state where u get a window with some options on the side and can then switch to code i cant remeber how to get there

Huh? o.O if you want a good reply, ask a good question (give details, IDE/Compiler... ect) and explain what you want clearly.

William Hemsworth 1,339 Posting Virtuoso

?!?!? that has to be one of the weirdest anime i have seen for a while i only just watched the first ep im too tired to watch anymore but i think, ill give it a couple more eps and to decide if i gonna watch anymore of it lol ..........

I've seen a few episodes of it before, I really liked the plot but for some reason never continued watching it. I may get back to it eventually.

William Hemsworth 1,339 Posting Virtuoso

I'm not entirely sure what it is you're trying to do, posting some code would help (or even a small example). Some other ways to simulate these events is to use mouse_event and keybd_event, as directly sending a message into a windows procedure can sometimes give you a different result to what your expecting. I'm not entirely sure what you mean by "The values for LPARAM and wParam for Keyboard is also easy, but I've no idea how to get the lParam for mouse events."

William Hemsworth 1,339 Posting Virtuoso

The Rasmus - One & Only

William Hemsworth 1,339 Posting Virtuoso

It took you three months to say thanks? ;) Fair enough.

William Hemsworth 1,339 Posting Virtuoso

An example:

#include <windows.h>

int main() {
  ShellExecute( NULL, NULL, "calc.exe", NULL, NULL, SW_SHOW );
}
William Hemsworth 1,339 Posting Virtuoso

The Goo Goo Dolls - Iris

William Hemsworth 1,339 Posting Virtuoso

The Get Up Kids - Campfire Kansas
I just never get tired of this song :)

William Hemsworth 1,339 Posting Virtuoso

The Eagles - Heartache Tonight

William Hemsworth 1,339 Posting Virtuoso

It has nothing to do with hooks.
Just use USB notifications.

Could this post have been any more useless? Of course it's to do with USB notifications, i'm just suggesting some area's to look at. If you're going to follow me to almost every windows based thread that I reply to, at least make the posts helpful by actually giving information as to how to solve the problem.

William Hemsworth 1,339 Posting Virtuoso

I think there's a special kind of windows hook for this. Look here for more information, though i'm not entirely sure, but it's worth a try.

William Hemsworth 1,339 Posting Virtuoso

You're weird ;)

William Hemsworth 1,339 Posting Virtuoso
jasimp commented: What's this "youtube" thing ;) +9
William Hemsworth 1,339 Posting Virtuoso

>i donno how it even works lol
Did you even write the code?

VernonDozier commented: Hit the nail on the head. +11
Salem commented: s/my dog ate my homework/my dog wrote my homework/ +29
William Hemsworth 1,339 Posting Virtuoso

>I hope someone likes it.
Sorry, not me :icon_cheesygrin:

William Hemsworth 1,339 Posting Virtuoso

>julienne is a nice name by the way, i will name my daughter like that if i have one oneday
Leave Narue alone! :<

William Hemsworth 1,339 Posting Virtuoso

Actually i dont understand why people dont want to show their faces in the forum?
we can take Dani as an example, she is the most preminent one and she does not need to hide her face.

What are you talking about? :) jbennet and I both show our faces. Check our profiles, it's just some people prefer not to have the whole of daniweb know their face.

William Hemsworth 1,339 Posting Virtuoso

Maybe because half DaniWeb members ARE children. How many members posting here are under 21 years old?

Heh, I think i've been pretty mature in this thread :)

William Hemsworth 1,339 Posting Virtuoso

It's easy to read pixels, like with the GetPixel function. But instead of reading each pixel individually, learn how to use BitBlt, to directly copy the window's entire device context to one you can use.

William Hemsworth 1,339 Posting Virtuoso

Not bad ;)

William Hemsworth 1,339 Posting Virtuoso

Funnily enough, I don't see any question marks in that post.
Oh well, it wouldn't make sense anyway.

Read This Before Posting

William Hemsworth 1,339 Posting Virtuoso
#include <iomanip>
#include <iostream>
using namespace std;

#ifdef __GNUC__
#include <unistd.h>
#endif

#ifdef _WIN32
#include <cstdlib>
#endif

int main()
{
  for (int units = 10; units > 0; units--) {
    cout << units;

    if (units < 1)
      cout << "\rBlast off!\n";

    cout.flush();

#ifdef __GNUC__
    sleep(1); // one second
#endif

#ifdef _WIN32
    _sleep(1000); // one thousand milliseconds
#endif

    [B]cout << "\r  \r"; // CR[/B]
  }
  return 0; 
} // main

You can erase what's already there with some white-spaces, then print the new number.

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

Learn how to post. Link