William Hemsworth 1,339 Posting Virtuoso

You can save the entire structure as binary, heres an exmaple of how to:

#include <iostream>
#include <fstream>
using namespace std;

template<typename type>
void SaveStruct(ofstream &out, type &obj) {
   out.write(reinterpret_cast<char*>( &obj ), sizeof type);
}

template<typename type>
void LoadStruct(ifstream &in, type &targetObj) {
   in.read(reinterpret_cast<char*>( &targetObj ), sizeof type);
}

struct A {
   char str[20];
   size_t str_len;
};

int main() {

   // Make Structure
   A a;
   strcpy_s(a.str, 20, "Hello World");
   a.str_len = strlen(a.str);

   // Save structure to file using SaveStruct(...)
   ofstream out("savefile.txt", ios::out | ios::binary);
   SaveStruct(out, a);
   out.close();

   // Load structure from file into the variable b
   A b;
   ifstream in("savefile.txt", ios::in | ios::binary);
   LoadStruct(in, b);

   // Display struct b
   cout << "str: " << b.str << "\nstr_len: " << b.str_len;
   
   cin.ignore();
   return 0;
}
William Hemsworth 1,339 Posting Virtuoso

Yay, 569ft!

Proof :)

William Hemsworth 1,339 Posting Virtuoso

Haven't you been to work experience yet ?
When I went to work experience, We (me and another friend) ended up getting a placement at Juiced Games for 2 weeks. That gave me a big experience of what programming can be like in a job. To be totally honest, it was a very relaxed environment, the only thing you had to watch out for is something called sprints. A sprint is a deadline to complete a task, and if you fall behind then I guess you have a problem. We also got to see a few of the programmers at work, and it looks like a lot of fun. Every 30-60 mins they would compile their new project and test for bugs. Some programmers would be developing the game itself, while others would be producing tools for the Artists to use.

I hope this answers abit of your question :)

William Hemsworth 1,339 Posting Virtuoso

> It'll be awhile before I can catch up to you in C++ and Assembly.
Im not to sure about that :) I barely know assembly at all but whenever I can be bothered, I try to learn some.

Alex Edwards commented: A Modest Pro =P +3
William Hemsworth 1,339 Posting Virtuoso

You need to show at least a bit of effort, not just dump a question and expect us to solve it, you haven't even said what your problem is. What do you expect us to do ?

William Hemsworth 1,339 Posting Virtuoso

-998

Almost there :)

William Hemsworth 1,339 Posting Virtuoso

Nope, I quite often delete my subscriptions, I also have 67 at the moment. Thanks but unfortunatly I dont think thats the problem.

William Hemsworth 1,339 Posting Virtuoso

Nope sorry, but its possible to clear the console buffer without using a system call. You will just have to look it up.

William Hemsworth 1,339 Posting Virtuoso

This isn't very related to the question, but mahlerfive, here is a few reasons why not to use system("pause") .

William Hemsworth 1,339 Posting Virtuoso

Read this.

William Hemsworth 1,339 Posting Virtuoso

Hah! how long did that last ?? a few hours ??

William Hemsworth 1,339 Posting Virtuoso

I dont understand whats happening, at first my link was working, then it stopped working and yours worked. Now its gone back to mine working and yours isn't ;) Somethings not quite right.

William Hemsworth 1,339 Posting Virtuoso

Im getting a strong feeling that you aren't going to be part of this community for much longer. :icon_neutral: Why don't you just do yourself and everybody else a favour and follow the rules... for once.

William Hemsworth 1,339 Posting Virtuoso

Dont listen to him The Dude! We all love your links :)

William Hemsworth 1,339 Posting Virtuoso

301, my god this is addicting >.<

William Hemsworth 1,339 Posting Virtuoso

32 :)

William Hemsworth 1,339 Posting Virtuoso

33 :)

William Hemsworth 1,339 Posting Virtuoso

is it gooooooooooooooooooood????????

Nope.. read Salems post...

William Hemsworth 1,339 Posting Virtuoso

Try to build SudoKu game. First try for 3 * 3 matrix. If you enter teo or three numbers in the block, it should automatically fill the rest of the fields. Really interesting.

I managed to make this with a 9 x 9 matrix (in C++ though), its really hard if you dont know what your doing! If you decide to do this, I found the best way to be, to make a 2D array (x,y) of vectors or arrays all containing possible candidates. When the vector is left with only one element the square is solved :)

William Hemsworth 1,339 Posting Virtuoso

haha xD, Australia "Kangaroos" :)

William Hemsworth 1,339 Posting Virtuoso

I started learning C++ (which is supposedly harder to learn than Java) at the age of 13, and im completely self taught. All it takes is a bit of time and effort, and it seems you just haven't put in the effort. :-O

Theres also plenty of resources over the web that could help you, so saying "My teacher didn't do a good job of telling us how to work on it" shoulden't really matter.

Salem commented: An awful lot of what I know, I figured out myself as well - good for you :) +20
William Hemsworth 1,339 Posting Virtuoso
William Hemsworth 1,339 Posting Virtuoso
William Hemsworth 1,339 Posting Virtuoso

haha, thats hilarious :)

William Hemsworth 1,339 Posting Virtuoso

really

(Miyuki Suzuki, ahh crap now I feel terrible >.< some one equalise him)

William Hemsworth 1,339 Posting Virtuoso

call

mate96 commented: # Never say impossible 'cause impossible itself says: "I M POSSIBLE":) :) :) #Your *I Can* is more important than your I.Q. +0
William Hemsworth 1,339 Posting Virtuoso

Any memory that you allocate should be deleted using the delete keyword otherwise it will case a memory leak. Even though AD has already said it, on line 26 you have assigned the pointer per to point at the characters "asdfgh" and you have ditched the 100 characters that you allocated on line 16. If you want to fill that array with a string, use strcpy.

William Hemsworth 1,339 Posting Virtuoso

try changing the line like this:

out.write(reinterpret_cast<char*>( &i ) , sizeof i);

That should save the integer, but this saves it in the form of binary, so its not readable if you open it in notepad.

William Hemsworth 1,339 Posting Virtuoso

-996

William Hemsworth 1,339 Posting Virtuoso

jail

William Hemsworth 1,339 Posting Virtuoso

Well.. whats your problem ?

William Hemsworth 1,339 Posting Virtuoso

I agree with Salem, I dont like to encourage cheating.. but heres somebody who has already solved this problem. Link

William Hemsworth 1,339 Posting Virtuoso

Look at this thread. Try asking for your username to be changed there.

William Hemsworth 1,339 Posting Virtuoso

flake

William Hemsworth 1,339 Posting Virtuoso

Maby a good idea would be to make a dialog appear just before submitting thats says (in a very big font) "USE CODE TAGS OR YOU WILL BE IGNORED OR YELLED AT!!!" for newbies who have less than 3-4 posts ? Perhaps that will get to em. ;)

William Hemsworth 1,339 Posting Virtuoso

I think the problem may be that the order of the posts is decided by time they were submitted, but not an an accurate enough level, mabey it should also sort the posts by seconds to get rid of this bug (assuming that thats how they are sorted).

William Hemsworth 1,339 Posting Virtuoso

Either way, isn't this a bug that should be fixed ??

William Hemsworth 1,339 Posting Virtuoso

Data stored in classes / structures is not seperated by anything, it can almost be though of as a complex array that can hold different data types. That is how you can use reinterpret_cast so that another structure, or even just an array can get the data from the structure. Look at this example:

#include <iostream>
using namespace std;

struct A {
	char a, b, c, d, e, f;
};

int main() {
	A a;

	a.a = 'H';
	a.b = 'e';
	a.c = 'l';
	a.d = 'l';
	a.e = 'o';
	a.f = 0;

	char *str = reinterpret_cast<char*>( &a );

	cout << str;

	cin.ignore();
	return 0;
}

It seems to me like your interested in alot of the low level details, So I suppose I could recommend this book (even though I haven't got yet, but I plan on getting). It will definitely give you some knowledge about how this stuff works, as it even teaches you how to write your own assembler. It also has very good ratings. But most of this will be based on assembly language so make sure you know a bit before buying this book :P

Hope this helps.

Alex Edwards commented: I understand reinterpret_cast a little better - thank you for that and the book recommendation! =) +3
William Hemsworth 1,339 Posting Virtuoso

I think you need to describe what it is your making and what your is problem a little better. Simply saying i'm stuck isn't enough.

William Hemsworth 1,339 Posting Virtuoso

Pffftt, its horrible ?? I honestly have no idea where you get this information from, it works doesn't it ??

William Hemsworth 1,339 Posting Virtuoso

snake

William Hemsworth 1,339 Posting Virtuoso

I have come across this problem a couple of times, if you reply to a thread, and then within a minute reply again, the order of the posts change like it has done for me in this thread.

http://www.daniweb.com/forums/thread140791.html

I dont know if anyone else has ever experienced this problem.

William Hemsworth 1,339 Posting Virtuoso

And I suppose you could be VERY evil and make it so the application automatically runs on startup :D

edit: Dont know why but this post has appeared before the main post :P

William Hemsworth 1,339 Posting Virtuoso

I wrote a slightly evil code, which I decided not to put up as a code snippet because it completely stops you from doing ANYTHING with the mouse or keyboard :) The only way to get out of it is to either log off (may only work on some computers) . or to shut down the computer. Be prepared before trying it out :D

The only thing you can't disable like this is the ability for the user to press CTRL-ALT-DEL

/*
 *  Make sure project type is windows application
 */

#define _WIN32_WINNT 0x0500
#include<windows.h>
#include<cmath>

LRESULT CALLBACK mouseHookProc(int nCode, WPARAM wParam, LPARAM lParam) {
   return 1;
}

LRESULT CALLBACK keyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) {
   return 1;
}

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nShowCmd) {

   // Set mouse hook
   HHOOK mouseHook = SetWindowsHookEx(
                  WH_MOUSE_LL,      /* Type of hook */
                  mouseHookProc,    /* Hook process */
                  hInstance,        /* Instance */
                  NULL);

   HHOOK keyboardHook = SetWindowsHookEx(
                  WH_KEYBOARD_LL,
                  keyboardHookProc,
                  hInstance,
                  0);

   // Wait for user to exit
   MessageBox(NULL, "Press OK to close.", "", MB_OK);
   return 0;
}

But just incase you want to be able to get out of it, you can make it so the user can exit the process be pressing the ESCAPE button, just change the keyboard hook like this.

LRESULT CALLBACK keyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) {
   PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT) (lParam);
   if (p->vkCode == VK_ESCAPE) {
      exit(0);
   }
   return 1;
}

Enjoy! :)

William Hemsworth 1,339 Posting Virtuoso

Whats the highest score you can get ??
Link
My best sofar is 1,113,870 :)

Have fun.

William Hemsworth 1,339 Posting Virtuoso

Bake

William Hemsworth 1,339 Posting Virtuoso

Why

William Hemsworth 1,339 Posting Virtuoso

Start here

William Hemsworth 1,339 Posting Virtuoso

I think Wiki_Tiki is using Windows Forms (.NET) . :)

William Hemsworth 1,339 Posting Virtuoso

I always wanted to know this;

Where does space end, and if it does not end, where does it go?

You can't think of space having an end. Imagine people haden't discovered that the earth was round, and somebody decided to go for a VERY long walk.. and eventually finds himself back where he origanally set off, he would be very confused and unable to think of an answer to what had happened. Thats why if you set off to space in one direction, you could somehow find yourself back where you started, without an explanation.