m4ster_r0shi 142 Posting Whiz in Training

I'm pretty sure the statement updating your population should be -> population *= (1 + annualBirth - annualDeath);

m4ster_r0shi 142 Posting Whiz in Training

Have you tried it? It works ok for me.

#define _WIN32_WINNT 0x0500

#include <windows.h>

bool IsPressed(int vkey)
{
    return GetAsyncKeyState(vkey) >> 15;
}

void MyMoveWindow(HWND hwnd, int dx, int dy)
{
    RECT wrect;

    GetWindowRect(hwnd, &wrect);

    MoveWindow(hwnd, wrect.left + dx, wrect.top + dy,
        wrect.right - wrect.left, wrect.bottom - wrect.top, TRUE);
}

int main()
{
    HWND hwnd = GetConsoleWindow();

    while (true)
    {
        if (IsPressed(VK_ESCAPE)) break;

        if (IsPressed(VK_UP))     MyMoveWindow(hwnd,   0, -10);

        if (IsPressed(VK_DOWN))   MyMoveWindow(hwnd,   0, +10);

        if (IsPressed(VK_LEFT))   MyMoveWindow(hwnd, -10,   0);

        if (IsPressed(VK_RIGHT))  MyMoveWindow(hwnd, +10,   0);

        Sleep(25);
    }

    return 0;
}

If you want to move a window other than your own, use HWND hwnd = FindWindow(0, "window name"); instead of HWND hwnd = GetConsoleWindow(); .

m4ster_r0shi 142 Posting Whiz in Training

Another good option is the ClipCursor function:

#include <windows.h>

int main()
{
    RECT old_rect; GetClipCursor(&old_rect);
    RECT new_rect = { 500, 500, 501, 501 };

    ClipCursor(&new_rect);

    Sleep(2500);

    ClipCursor(&old_rect);

    return 0;
}
m4ster_r0shi 142 Posting Whiz in Training

Lol... Glad to be of help, but the way mike suggested is simpler...

#include <iostream>

using namespace std;

int main()
{
    double val_1 = 1.56356;
    double val_2 = 1.56756;

    cout.flags(ios::fixed);
    cout.precision(2);

    cout << val_1 << endl;
    cout << val_2 << endl;

    return 0;
}
m4ster_r0shi 142 Posting Whiz in Training

Check this out:

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    double val_1 = 1.56356;
    double val_2 = 1.56756;

    cout << floor( (val_1 + 0.005) * 100.0 ) / 100.0 << endl;
    cout << floor( (val_2 + 0.005) * 100.0 ) / 100.0 << endl;

    return 0;
}

Useful link -> http://cplusplus.com/reference/clibrary/cmath/floor/

Another way:

#include <iostream>

using namespace std;

int main()
{
    double val_1 = 1.56356;
    double val_2 = 1.56756;

    cout << int( (val_1 + 0.005) * 100.0 ) / 100.0 << endl;
    cout << int( (val_2 + 0.005) * 100.0 ) / 100.0 << endl;

    return 0;
}
m4ster_r0shi 142 Posting Whiz in Training

You can use ReadProcessMemory:

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

using namespace std;

int main()
{
    char data[20] = "Hello, World!!!";

    char buffer[20] = { 0 };

    HANDLE my_process = GetCurrentProcess();

    unsigned long address = 0;

    cout << "(before) " << data << endl;

    while (true)
    {
        ReadProcessMemory(my_process, (LPCVOID) address, buffer, 20, 0);

        if (strcmp(data, buffer) == 0)
        {
            cout << "found it!" << endl;

            WriteProcessMemory(my_process, (LPVOID) address, "Yo! What's up?", 20, 0);

            break;
        }

        ++address;
    }

    cout << "(after) " << data << endl;

    cout << "(hit enter to quit...)"; cin.get();

    return 0;
}

[EDIT]

I didn't do it here, as this is just an example, but usually you'll
want to make few ReadProcessMemory calls with big buffers
instead of many ReadProcessMemory calls with small buffers.

It can make a huge difference in performance...

[/EDIT]

If you want to do this with other processes, you'll first have
to get the debug privilege and then use OpenProcess.

That's how you can get the debug privilege:

HANDLE my_process;
HANDLE htoken;
TOKEN_PRIVILEGES tp;
LUID luid;

my_process = GetCurrentProcess();
OpenProcessToken(my_process, TOKEN_ALL_ACCESS, &htoken);

LookupPrivilegeValue(NULL, "SeDebugPrivilege", &luid );

tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

AdjustTokenPrivileges(htoken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), 0, 0);

You can find additional info for all of these functions on MSDN:

http://msdn.microsoft.com/en-us/library/ms683179(v=vs.85).aspx (GetCurrentProcess)

http://msdn.microsoft.com/en-us/library/ms680553(v=vs.85).aspx (ReadProcessMemory)
http://msdn.microsoft.com/en-us/library/ms681674(v=vs.85).aspx (WriteProcessMemory)

http://msdn.microsoft.com/en-us/library/aa379295(v=vs.85).aspx (OpenProcessToken)
http://msdn.microsoft.com/en-us/library/aa379180(v=vs.85).aspx (LookupPrivilegeValue)
http://msdn.microsoft.com/en-us/library/aa375202(v=vs.85).aspx (AdjustTokenPrivileges)

sergent commented: You wrote A LOT +4
alwaysLearning0 commented: nice.. +4
m4ster_r0shi 142 Posting Whiz in Training

You're welcome :)

Note that the psapi.lib you got from Windows SDK should work too, but
you probably also need a psapi.dll next to your executable in this case.

m4ster_r0shi 142 Posting Whiz in Training

Are you sure the library doesn't exist in your MinGW folders?

I have the latest version of Code::Blocks/MinGW and I was able
to locate it here -> ...CodeBlocks\MinGW\lib\libpsapi.a See if you can find it, link to it and see if the problem persists.

m4ster_r0shi 142 Posting Whiz in Training

I tried to recreate the problem but I couldn't. Does this work ok for you?

#include <iostream>
#include <stdexcept>
#include <cassert>
#include <gsl/gsl_matrix.h>

typedef double real;

namespace gsl{

template< typename T >
class gsl_base
{
public:

    /// Get a pointer to the underlying GSL struct
    ///
    /// Will not throw, can return NULL
    inline T * ptr() { return M_pGSLData; }

    /// Get a const pointer to the underlying GSL struct
    ///
    /// Will not throw, can return NULL
    inline const T * const_ptr() const { return M_pGSLData; }

    /// Check if it's OK to try and manipulate the object
    ///
    /// Will not throw
    inline bool hasValue() const { return M_pGSLData != 0; }

    /// Check if it's not OK to try and manipulate the object
    ///
    /// Will not throw
    inline bool isNull() const { return M_pGSLData == 0; }

protected:

    gsl_base() : M_pGSLData( NULL ) {}
    gsl_base( T * original ) : M_pGSLData( original ) {}
    ~gsl_base() {}

    /// Set the value of the underlying GSL struct
    ///
    /// Will not throw
    inline void set_ptr( T * p ){ M_pGSLData = p; }

    T * M_pGSLData;

};

}

namespace gsl
{

class realMatrix : public gsl::gsl_base< gsl_matrix >
{
public:

	typedef real              value_type;
	typedef size_t             size_type;
	typedef real *              iterator;
	typedef const real *  const_iterator;
	typedef real &             reference;
	typedef const real & const_reference;
	typedef real *               pointer;
	typedef const real *   const_pointer;
	typedef ptrdiff_t    difference_type;

	struct M_matrix_element_type
	{
		realMatrix::size_type row;
		realMatrix::size_type col;

		M_matrix_element_type( realMatrix::size_type r, …
m4ster_r0shi 142 Posting Whiz in Training

What if you try std::cout << [B]M_pGSLData->data[/B] + i*[B]M_pGSLData->tda[/B] + j << " "; instead?

m4ster_r0shi 142 Posting Whiz in Training

map<uint16_t,set<float[U]>>[/U] <- This here means the OP uses Visual Studio ;)

This should work -> http://msdn.microsoft.com/en-us/library/0d462wfh(v=VS.90).aspx

m4ster_r0shi 142 Posting Whiz in Training

Google is a very good tool for this kind of things. You should really try using it more often :P Here's one of the
links I got by googling java remove multiple spaces -> http://stackoverflow.com/questions/2932392/java-how-to-replace-2-or-more-spaces-with-single-space-in-string-and-delete-leadi

m4ster_r0shi 142 Posting Whiz in Training

Try this:

//...

string = string.replace('\\', '/'); // replace \ with /
string = string.replace('\"', ' '); // replace " with space
string = string.trim(); // remove leading and trailing spaces

//...
m4ster_r0shi 142 Posting Whiz in Training

What do you mean when you say "special characters"?
And what do you mean when you say "space"?

Try this as your pattern -> [^A-Za-z\\s0-9] ( '\s' means space, tab, newline etc... )

Useful link -> http://download.oracle.com/javase/tutorial/essential/regex/

m4ster_r0shi 142 Posting Whiz in Training

Yes, it's a very good start. I like the fact that you noticed that you should print when the letters are different.
Also, even though I like the reputation I got from Narue, I'd like it even more if we could prove her wrong :P
I would do it in a slightly different way, so that I only need to print when the letters are different:

(aa)abbbddccc# don't print

a(aa)bbbddccc# don't print

aa(ab)bbddccc# print 'a'

aaa(bb)bddccc# don't print

aaab(bb)ddccc# don't print

aaabb(bd)dccc# print 'b'

aaabbb(dd)ccc# don't print

aaabbbd(dc)cc# print 'd'

aaabbbdd(cc)c# don't print

aaabbbddc(cc)# don't print

aaabbbddcc(c#) print 'c'

Now, let's try to write a C++ program that does this.

#include <iostream>
using namespace std;

int main()
{
    char my_string[] = "aaabbbddccc#";

    char current_letter;
    char next_letter;

    int i;

    for ( /* ... */ )
    {
        current_letter = //...
        next_letter = //...

        if ( /* current letter is different than next letter */ )
        {
            cout << current_letter;
        }
    }

    return 0;
}

See if you can fill in the missing code to make this work.

m4ster_r0shi 142 Posting Whiz in Training

If you don't print anything how will you get abdc???

I'll try one last time.

(aa)abbbddccc# print 'a' or don't print?

a(aa)bbbddccc# print 'a' or don't print?

aa(ab)bbddccc# print 'a', print 'b' or don't print?

aaa(bb)bddccc# print 'b' or don't print?

aaab(bb)ddccc# print 'b' or don't print?

aaabb(bd)dccc# print 'b', print 'd' or don't print?

aaabbb(dd)ccc# print 'd' or don't print?

aaabbbd(dc)cc# print 'd', print 'c' or don't print?

aaabbbdd(cc)c# print 'c' or don't print?

aaabbbddc(cc)# print 'c' or don't print?

aaabbbddcc(c#) print 'c', print '#' or don't print?

I want you to give me an answer on every question above.
And remember, I want the final output to be this -> abdc

Narue commented: Some people are lost causes. Props for being optimistic. +17
m4ster_r0shi 142 Posting Whiz in Training

Ok, I'll try to be more specific.

First, you see these two letters -> (aa)abbbddccc#
Then, you see these two -> a(aa)bbbddccc#
Then, you see these two -> aa(ab)bbddccc#
Then, you see -> aaa(bb)bddccc#

etc ...

I want you to tell me what you would do in each
case. Will you print a letter or not? And if you
print a letter, will it be the left or the right one?

Remember, I want the output to be this -> abdc

m4ster_r0shi 142 Posting Whiz in Training

To check whether the file exists or not, you can try opening it for input and see if it's open. If it's
not open, it means it doesn't exist. If it doesn't exist, opening it for output will automatically create it.

Here's some pseudocode:

open file for input (use an ifstream object)

check if the file is open using the is_open member function

if (the file is open) everything is fine

else 
{
    open the file for output (using an ofstream object)
    output a big value to the file (e.g. 10000),
    which will be the default high score
}
m4ster_r0shi 142 Posting Whiz in Training

Your program doesn't remove anything :P It just outputs the string omitting the first letter.
E.g., entering this -> aaabbbddccc will cause your program to output this -> aabbbddccc

Can you describe in english how you would remove duplicates from a string?

If I give you this string -> aaabbbddccc# and tell you that you can only access two consecutive letters at a time
and the only thing you can do after you see the letters is decide to either print or not print a letter, what will you do?

m4ster_r0shi 142 Posting Whiz in Training

It works for me. At least on the easy level. Are you sure the file exists?

Another thing. I noticed that if the old score has more digits than the new one,
some of the old digits remain to the file. To take care of this, use different objects
for reading and writing from/to the file. If I were you, I would create two functions:

//...

double read_score()
{
    double score;

    ifstream fin("score.txt");

    fin >> score;

    fin.close();

    return score;
}

void write_score(double score)
{
    // opening for output erases 
    // the contents of the file

    ofstream fout("score.txt");

    fout << score << endl;

    fout.close();
}

//...

double old_score = read_score();

//...

double new_score = //...
write_score(new_score);

//...
m4ster_r0shi 142 Posting Whiz in Training
//...

if(n1 < n2)
{
    cout << "You beat the high score of " << n1 << "." << endl;
    
    file.seekp(0, ios::beg); // move to the beginning of the file before writing
    file << n2 << endl; // I believe you want to write the new high score
}

//...
m4ster_r0shi 142 Posting Whiz in Training

I am having trouble of how to make the list move onto the next node.

You mean you have trouble popping the head?

This should do it:

create a temporary node pointing to head;
set head to point to the node next to it;
use delete on the temporary node above;

Don't you think you're getting a bit too much help here?
Are we going to share the grade you'll get on this? :D

m4ster_r0shi 142 Posting Whiz in Training

How can it use the function implicitly but not explicitly.

It can because the choice of the function to call isn't taken during compilation but while the program
is executed. Take a look at this here to see how -> http://en.wikipedia.org/wiki/Virtual_method_table

Also, note that this works ok:

//...

int main()
{
    derived d, *dp;

    dp = &d;
    dp->out();
    dp->base::out();

    return 0;
}
m4ster_r0shi 142 Posting Whiz in Training

when the base pointer points to derived object it prints i am derived

This is exactly what it's supposed to do.

Take a look at this:

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

struct Fruit
{
    virtual void Speak() {}
    virtual ~Fruit() {}
};

struct Apple : Fruit
{
    void Speak()
    {
        cout << "Hi! I'm an apple!\n" << endl;
    }
};

struct Pear : Fruit
{
    void Speak()
    {
        cout << "Hi! I'm a pear!\n" << endl;
    }
};

struct AnnoyingOrange : Fruit
{
    void Speak()
    {
        cout << "( http://www.youtube.com/user/realannoyingorange )\n";
        cout << "Hey Cabbage, know why you're so smart?\n";
        cout << "'Cause you have a big head. :D\n" << endl;
    }
};

template <class T>
void cleanup(vector<T*> v)
{
    for (unsigned i=0; i<v.size(); i++) delete v[i];
}

int main()
{
    vector<Fruit*> fruits;

    fruits.push_back(new Apple);
    fruits.push_back(new Pear);
    fruits.push_back(new AnnoyingOrange);

    fruits[0]->Speak();
    fruits[1]->Speak();
    fruits[2]->Speak();

    cleanup(fruits);

    cout << "hit enter to quit..." << endl;
    cin.get();
    return 0;
}

Also, take a look at this -> http://cplusplus.com/doc/tutorial/polymorphism/

m4ster_r0shi 142 Posting Whiz in Training

Ok. First, just to verify that this is where the problem comes from, try commenting out delete m_temp1; and delete m_temp2; and see what happens. Then, if these
two are indeed the cause of the problem, it would help a lot if you showed us the parts
of the code that involve m_temp1 , m_temp2 , m_HOBuffer and m_pBuffer .

m4ster_r0shi 142 Posting Whiz in Training

You mean CString::GetBuffer and CString::ReleaseBuffer ? I just checked the documentation on msdn...
(http://msdn.microsoft.com/en-us/library/aa314880%28v=vs.60%29.aspx, http://msdn.microsoft.com/en-us/library/aa300574%28v=vs.60%29.aspx)

...and it looks like you don't have to delete anything when you use CString::GetBuffer .

The buffer memory will be freed automatically when the CString object is destroyed.

So, if you delete[] memory you got with CString::GetBuffer , don't do it.

Also, note that CString::ReleaseBuffer does not deallocate the internal string buffer.

Use ReleaseBuffer to end use of a buffer allocated by GetBuffer.

m4ster_r0shi 142 Posting Whiz in Training

My best guess is that you delete[] memory that wasn't reserved with new[] .

Do the constructors of temp1 / temp2 set m_HOBuffer / m_pFileBuffer to zero?

Also, careful here:

temp2::~temp2()
{
    if (INFile.is_open())
        INFile.close();
    if (m_pBuffer) // either this should be m_pFileBuffer
        delete []m_pFileBuffer; // or this should be m_pBuffer
}
m4ster_r0shi 142 Posting Whiz in Training

I see.

AFAIK, when overloaded for streaming, the bitwise shift operators are supposed to represent the
data flow direction (let's call this rule number 1). That is, the arrowhead should point to the destination. cout << str; <- This means that data moves from str to screen. cin >> str; <- This means that data moves from keyboard to str.

I would explain the fact that << is associated with writing and >> with reading (rule number 2), simply using rule number 1
and the fact that i/o(f)streams are usually the leftmost term of a statement. If they are not, you can't apply rule number 2.

But, of course, that's just my view.

m4ster_r0shi 142 Posting Whiz in Training

@mike_2000_17:

I know. This was just an example to demonstrate how this could be made a member function. Thanks for the info though.

Yossi here sums up my opinion on overloading << and >> for i/o -> http://yosefk.com/c++fqa/operator.html#fqa-13.7

The idea to overload "bitwise exclusive or" to mean "power" is just stupid. I wonder where they get these ideas.
It's as if someone decided to overload "bitwise left shift" to mean "print to file". Wait a minute - they did that, too... Oh well.

EDIT:

especially since it inverts the normal semantics of C++ stream operators

What do you mean here?

This is not inverted semantics -> str >> cout; (string goes to cout)
This is inverted semantics -> str << cout; (???)

m4ster_r0shi 142 Posting Whiz in Training

Can you please explain why is this working?

Why shouldn't it work? I do it all the time :P In this case, the definition acts as a declaration too.

if I take of the friend from infront of the method name, it fails compiling

Well, operator << is a binary operator. This means it must take exactly two arguments. If you remove the friend keyword, you
make this function a member function. Now, there is an extra argument, the object for which it is called, for a total of three.

Something like this would work fine:

ostream & operator >> (ostream & stream)
{
    return stream << this->c_str;
}

You could call it like this:

my_string<char> str;

str >> cout;

Note that you would have trouble if you wanted to do this the usual way.
That is, provide the declaration in your class and the definition outside.

See why here -> http://cplusplus.com/forum/general/45776/

EDIT: Ah, right... I forgot that Koenig lookup is necessary for this to work...

m4ster_r0shi 142 Posting Whiz in Training

What you need is called dynamic memory allocation:

#include <iostream>

using namespace std;

struct Node {};

int main()
{
    int num_n;

    cout << "Enter number of nodes:\n";
    cin >> num_n;

    // Allocate memory dynamically

    Node * my_nodes = new Node[num_n];

    for (int i=0; i<num_n; i++)
    {
        // Set values of members of Node here

        // my_nodes[i] = ...
    }

    // Release memory when done

    delete[] my_nodes;
}

You could also use a vector:

#include <iostream>
#include <vector>

using namespace std;

struct Node {};

int main()
{
    int num_n;

    cout << "Enter number of nodes:\n";
    cin >> num_n;

    vector<Node> my_nodes(num_n);

    for (int i=0; i<num_n; i++)
    {
        // Set values of members of Node here

        // my_nodes[i] = ...
    }
}

Useful links:

http://cplusplus.com/doc/tutorial/dynamic/
http://cplusplus.com/search.do?q=vector

m4ster_r0shi 142 Posting Whiz in Training

Ok, I'll try to keep it simple this time. Let's start with something easy -> A calculator able to perform only addition and subtraction.

#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main()
{
    string expression;

    double result, number;
    char operation;

    while (true)
    {
        getline(cin, expression);

        if (expression == "") break;

        stringstream buffer(expression);

        buffer >> result;

        while (buffer >> operation >> number)
        {
            switch(operation)
            {
                case '+': result += number; break;
                case '-': result -= number; break;
            }
        }

        cout << result << endl;
    }

    return 0;
}

While there is available input, you get it and perform the appropriate operation. I believe this doesn't need more explanation.

If you're not familiar with stringstreams, it's a good idea to spend some time playing with them. Basically,
they provide an interface through which you can manipulate strings as if they were input/output streams.

Now, let's try to add multiplication and division to the above...

//...

while (buffer >> operation >> number)
{
    switch(operation)
    {
        case '+': result += number; break;
        case '-': result -= number; break;
        case '*': result *= number; break;
        case '/': result /= number; break;
    }
}

//...

2 * 5 + 1 evaluates to 11 , as we want. However, 1 + 2 * 5 evaluates to 15 .
The problem here is that our calculator lacks the concept of operator precedence.

A possible solution to this is to evaluate the expression in multiple steps - in …

m4ster_r0shi 142 Posting Whiz in Training

i want mine to be able to let you input unlimited operators

Well, this is not trivial.

This could be useful -> http://cplusplus.com/forum/lounge/42426/ (the code snippets are on page 2)
This could be useful too -> http://stackoverflow.com/questions/114586/smart-design-of-a-math-parser (see the best answer)

m4ster_r0shi 142 Posting Whiz in Training

What's wrong with this?

#include <iostream>

using namespace std;

int main()
{
    double number1, number2;
    char operation;

    while (true)
    {
        cin >> number1;
        cin >> operation;
        cin >> number2;

        if (!cin) break;

        switch(operation)
        {
            case '+': cout << number1 + number2 << endl; break;
            case '-': cout << number1 - number2 << endl; break;
            case '*': cout << number1 * number2 << endl; break;
            case '/': cout << number1 / number2 << endl; break;

            default: cout << "invalid operation character" << endl;
        }
    }

    return 0;
}
m4ster_r0shi 142 Posting Whiz in Training
m4ster_r0shi 142 Posting Whiz in Training

Yes, in this case multithreading is the way to go. Well, since I have never used pthreads either (I'm a windows guy), I can't help you on this.

m4ster_r0shi 142 Posting Whiz in Training

How about something like this then?

SDL_event_handling_proc()
{
    get event;

    if (event == quit) quit;

    if (event == escape)
    {
        hide sdl window;

        show console

        bring console to foreground;

        call interpret_lua;

        hide console

        show sdl window;
    }
}

If you're on windows...

For showing/hiding the console window see this:
http://msdn.microsoft.com/en-us/library/ms633548(v=vs.85).aspx

For bringing the console window to the foreground see this:
http://www.daniweb.com/software-development/cpp/threads/370728/1594255#post1594255

EDIT:

hmm a Quick Question if I have a loop(lets say loop1) and i have loop2 so loop2 is running inside loop1 does
loop1 actually continue looping or does it have to wait until loop2 is finished before starting its next iteration?

loop1 waits until loop2 is finished.

m4ster_r0shi 142 Posting Whiz in Training

If what you want is to make a GUI for a lua interpreter, I suggest handling all kind of input using SDL events.
Declare a buffer variable (char array or std::string) and when you get a keydown event modify it appropriately
(e.g. if a letter is pressed add it to the buffer, if backspace is pressed pop the last char from the buffer, etc...).
If the user hits enter, run the lua interpreter on your buffer.

m4ster_r0shi 142 Posting Whiz in Training

Well, are you really sure that the segafault is caused by the SDL
event handling procedure? What does your code look like now?

m4ster_r0shi 142 Posting Whiz in Training

There's a good tutorial on SDL here -> http://lazyfoo.net/SDL_tutorials/index.php

I modified some of the examples there, put them together and made this:

//The headers
#include <SDL/SDL.h>
#include <cstdio>

//Screen attributes
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;

SDL_Surface *screen = NULL;
SDL_Event event;

#undef main

int main()
{
    //Initialize all SDL subsystems
    if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ) return false;

    //Set up the screen
    screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );

    //If there was an error in setting up the screen
    if( screen == NULL ) return false;

    //Set the window caption
    SDL_WM_SetCaption( "event test", NULL );

    bool quit = false;

    while( !quit )
    {
        //If there is no event to handle, continue
        if ( !SDL_PollEvent( &event ) )
        {
            SDL_Delay(25);

            continue;
        }

        switch (event.type)
        {
            case SDL_QUIT:
                quit = true;

            break;
            case SDL_KEYDOWN:
                printf("a key was pressed\n");

            break;
            case SDL_KEYUP:
                printf("a key was released\n");
        }

        SDL_Delay(25);
    }

    //Quit SDL
    SDL_Quit();
}

Does this work for you?

m4ster_r0shi 142 Posting Whiz in Training

Check these out too:

http://en.wikipedia.org/wiki/INI_file#Accessing_INI_files
http://msdn.microsoft.com/en-us/library/ms724353.aspx
http://msdn.microsoft.com/en-us/library/ms724345.aspx

EDIT:

Though, your file doesn't seem to have the
correct format... You may have to change it.

m4ster_r0shi 142 Posting Whiz in Training

As mentioned above, the main use of constructors is object initialization. You may think that this is not an important job, but
consider this -> You want to create a vector of 10 vectors of 10 ints and you want to assign the value 25 to all of them (the ints).

The manual way to do this would be:

vector<vector<int> > my_container;

my_container.resize(10);

for (int i = 0; i < 10; ++i)
{
    my_container[i].resize(10);
    
    for (int j = 0; j < 10; ++j)
        my_container[i][j] = 25;
}

Using constructors, you just have to write:

vector<vector<int> > my_container(10, vector<int>(10, 25));

Which one do you prefer?

However, this is not the only use of constructors. Another thing you
can do with them is impose limitations on the ways your objects can
be created. There are cases where you want to disable copying for
your objects (because, let's say, you don't want to share ownership of
a resource). A special kind of constructor, called the copy constructor,
is invoked when you create a new object from an existing one. If you
make this constructor private, you make your objects non-copyable
(well, you also have to make the assignment operator private).

A real world example are the ostream and istream classes. Try to make a copy of
cout -> ostream cout_copy(cout); or cin -> istream cin_copy(cin); You can't. And what does the compiler say? error: 'std::ios_base::ios_base(const std::ios_base&)' is private within …

m4ster_r0shi 142 Posting Whiz in Training

However, the challenge was more of a dismissal of the nonexistent problem rather than an actual challenge that needs to be answered.

Well, then I guess it doesn't make sense to keep it a secret any more...

#include <iostream>

int main()
{
    char ch;

    // one semicolon == one statement :P :D

    std::cin.rdbuf()->sputbackc('\0'),
    std::cin.get(ch);

    std::cout << "'" << ch << "' ("
        << (int)ch << ")" << std::endl;
}

that's typically only meaningful when it comes to user input from the keyboard

Then, comment out line 9 above and hit CTRL-Z (CTRL-D in unixes) and ENTER.

m4ster_r0shi 142 Posting Whiz in Training

I believe this means she is asking you to input a null into the input stream.

Exactly! But she doesn't say that this must be done using the keyboard.

m4ster_r0shi 142 Posting Whiz in Training

I would think that you cant exactly enter a NULL character.

Oh, I see. Well, I never said I can enter a NULL character using the keyboard.
Neither did Narue say that this was the challenge. Wait, I'll PM you the answer.

m4ster_r0shi 142 Posting Whiz in Training

A char that has an integer equivalent of 0 is an undefined character on output isn't it?

I don't know. When I output it as a single char, I get a space. However,
when I use it to mark the end of a string (0 == '\0'), nothing is printed.

m4ster_r0shi 142 Posting Whiz in Training

I challenge you to input a character with the value of 0 using cin. It's not as simple as you might think.

Assuming I have a char variable declared, I can do this in one statement.

m4ster_r0shi 142 Posting Whiz in Training

Mmmm... You shouldn't add anything to your list when you encounter an 'S'.
Your list should only consist of 'R'-type nodes. When you encounter an 'S',
you should just modify the head node (which should be an 'R' node, since
you only add 'R's to your list) and perhaps remove it (if its quantity drops
to zero). Also, note that the check you do to remove the head should be
independent from the checks you do to update the head quantity. That is,

it should be...

if (head->quant > d_quant) { /*...*/ }
else if (head->quant <= d_quant) { /*...*/ }

if (head->quant == 0) { /*...*/ }

instead of...

if (head->quant > d_quant) { /*...*/ }
else if (head->quant <= d_quant) { /*...*/ }
else if (head->quant == 0) { /*...*/ }

Finally, when you decrease head->quant , you should also decrease d_quant by
the same amount, or else this -> while ([B]d_quant!=0[/B] && head != 0) won't work.

I am getting confused the more I look at the code.

Then don't look at the code. Get a pencil and a piece of paper and
write your algorithm in english. After you make sure it does what it's
supposed to do, converting it to C++ code shouldn't be a problem.

m4ster_r0shi 142 Posting Whiz in Training

I use this code

What for? Bringing the console window to the foreground? Doesn't my code work?

what does the zeroes mean?

Everything is explained here -> http://msdn.microsoft.com/en-us/library/ms646260(v=vs.85).aspx

Is there a better way to do it?

Sure, use SendInput instead -> http://msdn.microsoft.com/en-us/library/ms646310(v=vs.85).aspx

You can find all the information you need about windows functions on that site.

m4ster_r0shi 142 Posting Whiz in Training

I need #define _WIN32_WINNT 0x0500 because I can't use GetConsoleWindow otherwise.
See the remarks section here -> http://msdn.microsoft.com/en-us/library/ms683175(v=vs.85).aspx HWND is nothing but a typedef for HANDLE , which in turn
is a typedef for PVOID , which in turn is a typedef for void * See here -> http://msdn.microsoft.com/en-us/library/aa383751(v=vs.85).aspx

So, hwnd is a pointer to the console window. I need this
because I use it as an argument to SetForegroundWindow.

The program I wrote brings the console window up every three seconds.
Run it, then click somewhere so that the console window disappears, then wait.

Oh, and you can exit the program anytime by hiting esc.