Ketsuekiame 860 Master Poster Featured Poster

Maybe, opening the files with ios::trunc opening mode open would help.

ios::out implies ios::trunc when used with ofstream.

My problem was a plug-in setting I was using, as for the original problem. That lies within the FileFilter class and the getline loop.

OP: Just another point, you aren't capitalising A's and Z's :) Check your if statement again.

Ketsuekiame 860 Master Poster Featured Poster

Ah my bad, I have my custom VS plugin set to throw when "GetLastError" changes ^^

I can read and write to the files fine, but your getline method in FileFilter doesn't work properly.

=)

Ketsuekiame 860 Master Poster Featured Poster

Actually I was incorrect...

I've just tried running your code with a few debugging additions.

It appears ofstream.open does NOT behave as documented. ofstream.open is returning error code 183. Which means
"Cannot create a file when that file already exists."

However, the expected behaviour is that it should open the file and empty it.

I'm not sure why this is, I generally use FILE for working with files. I'll look into it.

Ketsuekiame 860 Master Poster Featured Poster

Ok, I see the problem.

It's the way that you are handling the file reads. Please look at how getline handles what you are asking for.

Google will help you there :)

Ketsuekiame 860 Master Poster Featured Poster

Ok I'll help...


Choose a different course. =/

Ketsuekiame 860 Master Poster Featured Poster

Look up strings and their manipulative functions. You should be able to split the string into its separate words and count the result.

Nick Evan commented: Sounds like a plan +12
Ketsuekiame 860 Master Poster Featured Poster

The problem I was getting at is not important, but I didn't want to point it out in case that *was* the home work ;)

You aren't closing your open file handles. It's not strictly necessary but can cause some strange behaviour including memory leaks and locked files. Generally this gets seen and the file is closed when the method exits. I just weren't sure in your case.

Now you've said you're worried about the cin call you had. Could you post how you had it before?

I would use

cin >> variable;

You can also use

cin.get();

to return the first character, but you must empty the buffer to get more as subsequent calls to cin.get(); will return the first character you entered.

Apologies for seemingly being rude in my first post. It wasn't my intention, but after re-reading it I can see how it may be interpreted that way.

Ketsuekiame 860 Master Poster Featured Poster

The only thing close is to use Triggers. Triggers are fired on an event you specify. The only problem is they can't connect back to your code.

The only possible combination is to use triggers with a messaging server using plugins that can be found in the UDF Sources. This way the trigger can notify the messaging server and the server can notify your application.

Unless someone has already written one for C#...But I couldn't see one.

Ketsuekiame 860 Master Poster Featured Poster

PHP is becoming more OO...It is! Really!...

I know I'm deluding myself ^^

Ketsuekiame 860 Master Poster Featured Poster

Using static cast is a pretty efficient way of casting.

I think the only alternative method you have is to put some decision making logic in there so that func2 knows which function to call.

Ketsuekiame 860 Master Poster Featured Poster

thelamb is correct in his statement. I've modified the code below.

class A {
public:
  virtual void func1() {cout << "A: func1" << endl;}
  void func2() {A::func1();}
};
 
class B: public A {
public:
  void func1() {cout << "B: func1" << endl;}
  void func3() {A::func2();}
};

Personally, I don't see the point in what you're trying to achieve here and I think you have more of a design issue than a development issue =/

(eg. making func1 private and possibly func2 protected? Then func3 calls func2 which calls func1 (private) but again, it's hard to see why something like that is required from what you've given us.)

Ketsuekiame 860 Master Poster Featured Poster

tinyint is already unsigned. It is a just a single byte of value 0-255.

A point to remember if you ever need to translate to MySQL is that MySQL stores tinyint as SIGNED by default, whereas MS SQL stores it as UNSIGNED by default.

You can cast between the two in code (providing you do sufficient checks first)

Ketsuekiame 860 Master Poster Featured Poster

I would begin by designing something that could become quite large.

I don't mean full scale design though.

For example. I would treat everything as a GameObject where GameObject has some basic data like "Description", "Position" etc and some basic functionality like "PrintDescription", "Push", "Pull" etc.

Then specify more; so if you had a Banana and a Room.

public class Banana : GameObject
{
    // Still have all GameObject methods etc
    StepOn(){ Console.WriteLine("You slipped on a banana!");
}

public class Room : GameObject
{
    // Still have all GameObjects basic stuff
    public WalkNorth();
    public OpenDoor(int doorNumber);
}

etc etc.

This way you can componentise just about every aspect, meaning less repeated code.
(eg. you only have one PrintDescription method rather than 20 with different text in)

I would bear this in mind when you start coding it again =)

Antenka commented: Good job. Stimulating newbies to prevent the coding with desing would save a lots of time :) +2
Ketsuekiame 860 Master Poster Featured Poster

You say you think there is a memory leak. What is giving you that impression?

There is a mistake in the code, it won't stop it working and it's so glaringly obvious I'm reluctant to point it out =/

Ketsuekiame 860 Master Poster Featured Poster

tnks for your replies!

@katsuekiame, yes you're right, I was trying to access the printer port's memory! I'm trying to learn how to control the printer port so that I can control a primitive flatbed plotter I've built from old printer parts (just for fun)...

@chiwawa10, I was trying to access that specific memory location because I had to access the printer's memory register...

btw, does anyone know what are memory segments?
The thing is, I can access memory addresses very easily with QBasic's peek and poke functions, but before using any of those functions, you have to use the DEF SEG function (QBasic's on-line help defines this function as 'a memory statement that sets the current memory segment address for a subsequent PEEK or POKE function')

so the following code in QB:

DEF SEG = 0
PEEK (888)     '888 is the decimal equivalent of 0x378

is different from this:

DEF SEG = 1
PEEK (888)

I need to know which memory segment I need to use to access the right address...
Tnks again!

DEF SEG gets a segment of memory. In QBasic this is the high-order 16bits from the memory segment you wish to work in.

The peek and poke then works with the low-order 16 bits.

So your code effectively sets the high order segment to work with to 0, and then requests what's being held at memory address 0x378 (888 to hex is 0x378)
The following will read the memory from address 1234ABCD:


       
Ketsuekiame 860 Master Poster Featured Poster

From the compiler errors you've tried to instantiate an abstract class.

Abstract classes cannot be instantiated and must be inherited.

This is an abstract class:

class MyAbstract
{
public:
     virtual void PrintLetter(char letter) = 0;
}

To use an abstract class you must inherit it and override the virtual function

class MyClass : MyAbstract
{
public:
     void PrintLetter(char letter) { std::cout << letter; }
}

To apply this specifically to your code. Your GameState class has an abstract function called "Cleanup". You must inherit GameState into your own class and override the "Cleanup" method.

Secondly, you've tried to use the method "Clean". This doesn't exist in the GameState class at all.

Have you copied the code from the tutorial and tried to compile it before completing the tutorial?

Ketsuekiame 860 Master Poster Featured Poster

You must use 'delete' on every 'new' variable. Thus the second is one to follow. It is a good practice to make your pointer to point to NULL after you have deleted the object to prevent your pointer pointing to unspecified location.

void SomeClass::someMethod()
{
     AnotherClass *object = new AnotherClass();
     object->doSomething();
     delete object;
     object = null;
}

This is useful when you want to reuse your pointer at a later stage.

Indeed, not assigning to NULL is commonly referred to as a dangling pointer and can cause all sorts of weird behaviour if you assume it's still assigned.

Ketsuekiame 860 Master Poster Featured Poster

Ok, I think you'll need a file called inpout32.dll

Check this link for all the information you should need

Ketsuekiame 860 Master Poster Featured Poster

You have to do the second one.


EDIT: For memory leak diagnostics I recommend using Visual Leak Detector (if you're using Visual Studio)

EDIT 2: The reason you must delete, is that if we take your code as an example, you create an instance of the point "AnotherClass" and assign it some memory. You then do stuff with that class and the memory it points to. Then you exit the function and everything gets de-referenced. So you no longer have a pointer to your memory address that contains the "AnotherClass" class. This memory, however, is still assigned and in use (by your class) but you no longer have any method of getting to it. You have a "lost pointer".

Similarly if you re-assign the pointer before deleting it.

void SomeClass::someMethod()
{
     AnotherClass *object = new AnotherClass();
     object->doSomething();
     object = new AnotherClass();
     delete object;
}
Ketsuekiame 860 Master Poster Featured Poster

Hi there!

Am I correct in assuming you want to access the parallel port?
You may be better using CreateFile("LPT1",GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,NULL);

Then using ReadFile and WriteFile to read and write data over the port using the handle that "CreateFile" generates.

The reason you cannot access it directly is because it exists in an area of memory that User Mode applications are not allowed to access. If you wanted to get access to this specific address, then you *must* write a device driver to do it.

Ketsuekiame 860 Master Poster Featured Poster

Hi there, this is a notification to the guys who that that ++i would start at "1" whereas i++ would start at 0.

This is an incorrect assertion. The difference between ++i and i++ you are correct to a degree. ++i does addition before assignment and i++ does assignment before addition.
However, only the variable i is being assigned to. This means that the order of operation is not important.

Here is an example for loop:

for(int i = 0; i < 10; i++)
{
    Console.WriteLine(i);
}

Let's take the first line. On the first iteration the first argument is read. "int i = 0"
This creates the variable i of int type and assigns it to 0. It then reads the second argument, which is an if statement (effectively). If i is less than 10, perform an iteration, otherwise exit the loop.

The third argument is what should happen at the end of an iteration.

1. How should I begin?
2. When should I continue?
3. What should I do at the end of an iteration?

So back to the difference in ++i and i++. In this case there is none.

int i = 10;
int j = 10;
i = i++;
j = ++j;

In this case. If you printed out "i" it would read "10". If you printed out "j" it would read "11"

In self assignment (which a for loop uses)
i++ and …

Ketsuekiame 860 Master Poster Featured Poster

As you've quoted me I'm unsure if that post was directed at me or not. However, to prevent a misunderstanding if you were directing it at me, I wasn't trying to recommend the OP use vectors. I was actually saying he should be using simple arrays. The post itself was primarily directed at Scu and not the OP. As such, after that post, we continued our discussion in PM.

If it wasn't directed at me, then i apologise for making you read this text =)

Ketsuekiame 860 Master Poster Featured Poster

Then you'll need to design some decision making to work out which strings go in which array list.

Only you really know the answer to that one ^^

Ketsuekiame 860 Master Poster Featured Poster

Please see the post above your last. That is the correct method.

Remember you can use variables as your key name, they don't have to be quote marked.

string str = "bob";
hashtable["bob"];
hashtable[str];

Choosing either of the above will give you the same result.

Ketsuekiame 860 Master Poster Featured Poster

@Scu: To answer your question directly, it's pointer based. The way they work is actually very efficient and in 99% of cases I would recommend using vector/list.

There are a couple of downsides. Firstly, they don't tend to de-allocate memory once it has been allocated (like in my above post) this makes it quicker to add and remove items.

They are also inefficient at storing plain data (anything that isn't a class or complex struct).
(Storing an int = sizeof(int), invoking vector = sizeof(vector<int>) + (vectorcount * (sizeof(pointer) + sizeof(int)). Then you also have allocation, reallocation + error checking...)

I do use the word inefficient in the loosest context I can though. Comparatively speaking on modern machines the time difference is microseconds for large arrays. This is the trade-off for flexibility and functionality such as iterators.

If memory is not an issue and you're running on a fast machine there's no reason not to go with them for complex and large arrays. On a single dimensional array of 10 ints...There's no point choosing anything other than an array of int =)

Ketsuekiame 860 Master Poster Featured Poster

You could use the

vector<int> variable;

statement and have more control over it. Even changing the size, not passing the length to the function through a variable and can use other userful functions contained in the vector class.

A good idea, but based on the type of question, the OP should be warned about the additional overhead incurred by invoking the vector class.

Also, care should be especially taken when popping items off the vector, as the memory allocated for the previous size of the vector is not released (if you have 100 items and pop 50 off, the vector is still allocated enough memory for 100 items, even though it only contains 50)

Looking at the OP's question, the application could be memory critical. Passing pointers is the most memory efficient way of working with arrays.

Ketsuekiame 860 Master Poster Featured Poster

A much cleaner way would be to initialise your images and associate the Tag property with their name:

Image imgOne = Resource.YourImage;
imgOne.Tag = ImageNameString;

Then initialise your Image List:

List<Image> imageList = new List<Image>{// Your Images};

Then initialise your PictureBox list:

List<PictureBox> pictureBoxList = new List<PictureBox>();

Ok now we have the basics set up. Begin assigning randomly. Once one picture has been assigned to the picture box, remove it from the list:

while(imageList.Count > 0)
{
     int imageIndex = //random number between 0 and (imageList.Count - 1);
     PictureBox tempBox = new PictureBox { Image = imageList[imageIndex], OnClick = PictureBox_Click };
     picturBoxList.Add(tempBox);
     imageList.RemoveAt(imageIndex);
}

Ok, now remember how the Tag was set before? This stores any information you want. It takes the Object type so you can box and un-box. In this case we've saved a string (your image name).

In order to make a comparison, include a Private PictureBox variable to your form. Here you will save your first selection.

When you make your second selection, compare the tags (you can convert them to strings first, I have assumed you'll be doing this in a Form Wide PictureBox_Click event):

private void PictureBox_Click(object sender, EventArgs args)
{
     // Psuedo code, I don't want to give it allll away ;)
     // Check if first selection variable is null
     // If true, cast sender to PictureBox, store in first selection variable and return
     // else, perform the code below
     String firstString = (String)firstSelection.Image.Tag;
     String secondString …
Ketsuekiame 860 Master Poster Featured Poster

There are basically two methods of interaction for MFC.
AFXSocket (which is the MFC implementation of winsock2) or socket (C-Style library for winsock2)

First you need to set up your method of communication, then choose which type of transmission protocol (TCP/UDP) and finally decide on your application protocol (how it receives/parses/transmits messages)

For more information than that I recommend you use Google as there are plenty of tutorials out there for both afx and standard sockets.

Ketsuekiame 860 Master Poster Featured Poster

Personally, if you wanted to do that, I would pass a pointer to the array and the array's length.

void someFunc(double* myArray, long arrayLength)
{
     // Do stuff with array using arrayLength to ensure no out of bounds exception
     // Also note any changes made in here will be reflected in the original array.
}
Ketsuekiame 860 Master Poster Featured Poster

Both of those are good libraries, but Axiom is most definitely overkill unless they are writing a full blown game (the learning curve is very steep)

TV3D is probably the best bet, unless all you want is to render to a form in the most basic fashion.

Have fun in 3D. I think it's one of the most interesting parts of development :)

Ketsuekiame 860 Master Poster Featured Poster

So if I understand you.

You have a list of nodes, and in each node you have 20-ish variables of data (in an array?)

When you perform the List::Compare function you want it to compare a set of numbers you choose, with every variable of data in every node of your linked list?

Ketsuekiame 860 Master Poster Featured Poster

Hi there,
it looks like you want to be using DirectX (or the Tao OpenGL Libraries).

A tutorial for DirectX in C# can be found here

Ketsuekiame 860 Master Poster Featured Poster
DbProviderFactory factory =
    DbProviderFactories.GetFactory("System.Data.OleDb");

DataTable userTables = null;

using (DbConnection connection =
            factory.CreateConnection())
{

    connection.ConnectionString = "Provider=Microsoft
        .Jet.OLEDB.4.0;Data Source=" & file;
    
    // We only want user tables, not system tables
    string[] restrictions = new string[4];
    restrictions[3] = "Table";
    
    connection.Open();
    
    // Get list of user tables
    userTables =
        connection.GetSchema("Tables", restrictions);
}

// Add list of table names to listBox
for (int i=0; i < userTables.Rows.Count; i++)
    listBox1.Items.Add(userTables.Rows[i][2].ToString());