jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use a .NET container instead. You can use a System::Collections::ArrayList (wbich stores things as type "object" -- they must be casted back to their original type to be used) or a System::Collection::Generic::List . I was looking for an article that explains the difference between managed and unmanaged code for you but the ones I found were a bit outdated. See http://en.wikipedia.org/wiki/C%2B%2B/CLI for an "ok" overview.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Line 17 is: for ([b]numbers >= 1[/b]; counter <= numbers; counter++) The first slot in the for loop is used for initialization of the counter variable. What you have there is a conditional statement (like the one in the middle slot of the loop) that evaluates to true or false. If you're not using the loop counter for anything beyond the body of the loop, simply declare it in the first slot and it will disappear after the loop ends (and omit line 12). for(int counter = 0;counter<=numbers;counter++) For the variable to remain intact after the loop you can omit the first slot and leave line 12 as it is. for(;counter<=numbers;counter++) For the sake of completeness you could also declare it on line 12

int counter;
//...then on line 17
for(counter=0;counter<=numbers;counter++)

Other than that it seems to be ok (I did not run it). Check that it gives the correct results after making the change.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Definitely a spammer.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Even if you have the library set up properly it's going to be a chore to exchange all the unmanaged and managed data. See http://gregs-blog.com/category/ccli/ for a good example of using the marshal technique. Especially with moving large arrays back and forth as you would for the images it could get tedious.

Did you successfully read in the .pgm file into an array?(from you other post) I would make sure you've got that down first and worry about displaying it in the picturebox later on. See http://en.wikipedia.org/wiki/BMP_file_format for a description of the bitmap format, as you can probably build a bitmap out of the grayscale data that you get from the PGM. Consider that other option that I gave you also where you make a picturebox out of a bunch of little contiguous pictureboxes each one representing a pixel.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try opening file like this:

fstream outStream("test.txt", ios::in|ios::out)

That gives better numbers from the seekg function but I think the OP needs to have the append setting on. I suppose the position could be reset after the read is made.

This fares no better in returning the proper string using his original -11.

I think I'll bow out of this one.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, you are declaring the labels array locally within the scope of the constructor. Place the array<Label ^>^ labels; with the other private variables of the form, that way it's local to the whole class.
I didn't understand that was a missing piece I was focusing on the logic of your method.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I've done some experiments with tellg to get the file position after the seekg and it keeps coming back with -1 all of the time. I recalled something about seekg being problematic with text files. I found http://msdn.microsoft.com/en-us/library/y2d6fx99.aspx (scroll down to the yellow box) saying that the offset/seekdirection form shouldn't be used with text files. I'm no expert in this area so I couldn't give you the final work on how true that is.

I would say (and this definitely is not efficient) but open the text file with ios::in, read line by line until the last entry,do your checks,close the file and open it back up again for output (and with append).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

i have already opened the file with ios::app.So the get and set pointer is already at the end of the file.

Didn't put 2 and 2 together, apologies

*I want to open that file in append mode and then i want to print the last line of that file.

I understand the immediate task at hand. I'm trying to get a handle on the big picture. I meant that I don't understand the constraints that are preventing you from opening the file without the append and seek back from the end (since maybe there is another way).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try merging linkedlist.cpp into linkedlist.h (see http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12) queuelink.h seems to be in the right format.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Update: This is doable with reading in the PGM as text, line by line.
It is possible to convert the pgm into a bitmap (there is an existing library http://netpbm.sourceforge.net/doc/libnetpbm.html but dealing with the managed/unmanaged interface might be tedious).

If all you need is a way to display the image then make an array of pictureboxes each one as a "pixel" and change the background of the PB to the appropriate grayscale value.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The best person to ask for the definition of "system hanging" would be the one that gave you the assignment. There's some ambiguity to the term.

I think the whole idea seems suspect but maybe it's me.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm not entirely clear on what you need done. If you want the last line you should probably use ios::end instead of ios::cur

nbaztec commented: You noticed what I didn't. :) +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

FunctionX (http://www.functionx.com/vccli/index.htm) has some decent tutorials for learning the C++/CLI language (the dialect of C++ used with the .NET library) but their winforms tutorials lag behind a version or two.

It seems to be far easier to find C# references for this. I looked for a bit and couldn't find the walkthroughs on MSDN for VC++ or VC# but they usually have videos to show you a basic winforms program. If you can figure it out using C# it doesn't take too much effort to translate it back to C++/CLI.

Play around with it on your own and pop textbox and the button up on the form. Double-click on the button to generate an event handler. That code will execute every time you hit the button. Access the text portion of your textbox via YourTextBox::Text and set it equal to "Hello World." There are some nuances with the strings (look up "handles" to get some idea of the "^" operator) but you shouldn't have to worry about those to start.

It helps to use 2008 over 2010 because they totally scrapped the Intellisense for C++/CLI in 2010 (at least in the express edition but I'm fairly certain in the full versions as well).

I wish I could have given you a better tutorial to follow but post back if you have any difficulties.

EDIT: LOL at AD ^^^^^^^ but there aren't many good ones for the winforms in C++.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What do you mean by register?

How is it declared?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What's not transferring over from the C# properly? In doing this I realize it would be nice for C++/CLI to have an "is" keyword.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Is this what your other thread is about too? I posted on that one. Try to keep it in the one thread if it's all the same issue. That way nobody gets confused.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What does the file contain? (text or binary)
If it's text, look up StreamReader and read it directly into a string in one fell swoop with the ReadToEnd() method.

If you use ToString() on an object that does not have an override for that method you get the class name back.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I still think it might be easier to do it label by label (you would only need one event handler). If you have the Tag free (it looked like you were using it for something before) you could tag the label with its position in the array and use that to compare to the sender. That way you wouldn't need the position information.
I think it could work your way I'm just not coming up with it, though.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Well, we could have calculated size before hand (if you knew it wasn't going to change and especially if you had an immense vector that would be advisable). If you had an array that had elements 10,20,30,40 and you had the same exact loop you could just say i<4, but the vector has some machinery behind the scenes that keeps track of each item that you add (not unlike a std::string having a length member and a way to access it). Tell me which part is troubling you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Where is itemCurrent coming from in your code above? Seems to me you could match your sender to the desired control and run another static method when that is true.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

All there in lines 2-5 above. The ith element of the vector is accessed via vec[i] assuming your vector is named vec (so if you have declared vector vec<int>; earlier.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

To get the Y value, int y = e->Location.Y; Do you need to know the location and change the label simultaneously? I think it's much easier to handle the color change with a mouse_enter and mouse_leave event of the label rather than the form. However, in doing so the eventargs of the mouse_enter does not have position information any longer.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Sure. Here's an example in a for loop (vec.size() returns an element of size_t, which is usually defined as an unsigned int, so we'll make the loop variable size_t as well).

So you've done your while loop and vec has N elements. vectors store this value within the data structure.

int sum = 0; //again change for double or whatever your values are
for (size_t i = 0;i<vec.size();i++) //vec.size() accesses that property = N
{
   sum+=vec[i];
}

You could use an iterator with the vector also but this is less involved.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Make a class for a "player" and a "game" to go along with "room" (obviously you need many other classes but this gives a foundation). Have "game" instantiate an array of rooms and a player object.

Try to go a bit further and come up with some code and we can definitely help you with that.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use vec.size() to get the number of entries. Your vec is a vector<int> so your storage is already taken care of (if you're doing doubles or something else just change the type of vector).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Store them in a std::vector and use a while loop to get the input:

int temp;
while(cin >> temp)
{
   vec.push_back(temp);
}

and have the user push ctrl-z (or ctrl-d on *nix) when they are done.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

(which I guess means a defult zero?)

Unfortunately it can be just about any value that is sitting in that memory location. Visual C++ initializes some values in Debug mode but it's a much better idea to initialize. When using a counter it is usually set to 0.

Increment number_of_users after you have assigned the array values. That way you are starting at 0 and putting your values into position 0.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Within the body of a button click method (of a button with the text "Open" or some such)

openFileDialog1->InitialDirectory = "C:\\";  //set the initial directory for the dlg
openFileDialog1->Filter = "All Files(*.*)|*.*"; //set a filter for the types of files
openFileDialog1->FileName = ""; //leave the textbox blank
Windows::Forms::DialogResult dr = openFileDialog1->ShowDialog(); //show the dialog

After that, compare dr with Windows::Forms::DialogResult::OK (need the fully qualified name) and openFileDialog1->FileName will contain the name file the user selected. Use this name, for instance, in a StreamReader call to open a text file.

See http://msdn.microsoft.com/en-us/library/system.windows.forms.openfiledialog_members.aspx to get an idea of some of the other members that are available.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
userfile << users[number_of_users] << "\n";
userfile << UserDifficulty[number_of_users] << "\n";

You are one past the end on these arrays.

I agree with nbaztec there is probably something going on when you are entering the values especially if the output is not consistently wrong.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Does the output from your first section of code come out correctly? See if you can pinpoint where in the process the garbage is printed. If the output for that first section is not correct check and make sure your arrays are holding that many elements.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Please use code tags [code] //code here [/code].

Your sort function is not actually sorting anything. You should pass in the array of structs and not return anything. Look up bubble sort and you should find lots of examples, but basically you do

temp = a
a = b
b = temp

with the array elements (you can assign the structs directly to one another).

The best thing to do is create and test each of your functions separately and then integrate the whole package.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The approach will be exactly the same as in your other thread (http://www.daniweb.com/forums/thread292268.html).

Are you having a specific problem implementing what those other posters suggested?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There are a few options and probably some others that I have forgotten about.

The easiest is to keep the program like you have it (although you have a mismatch in the if/else pair which needs to be fixed) and after you've stepped through the char array with the while loop, compare x to 10, if the 2 are equal it's a valid number. Check the condition of your if statement because it's incorrect, you want numbers that sit in between 46 and 58 rather than anything >46 OR <58.

Another option is to change number to an integer and use the fail bit of the input stream (see second code sample on this site http://www.cs.utk.edu/cs102/lectures/cinLecture.html). If any alpha characters are put in the stream will fail and you can check for that and loop back for more input.

There's also strtol (include <cstdlib>) which can be used on your char array input and the function will return a value if there's a successful conversion. See http://www.cplusplus.com/reference/clibrary/cstdlib/strtol/

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Rather than use itoa which is non-standard try nbaztec's stringstream method:
(portions omitted)

#include <sstream>
//...
std::stringstream ss;
for
{
  for
  {
    for
    {
       ss.str("");  
       ss<<i<<","<<j<<","<<k;
       std::cout<<ss.str()<<std::endl;
     }
   }
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It might work if you use the partial keyword.

In the first file:

namespace DaniWeb
{
   public partial class MyClass
   {
        public int Method1()
        {

        }
    }
}

In another file:

namespace DaniWeb
{
   public partial class MyClass
   {
        public void Method2()
        {

        }
    }
}

Otherwise like you said, you'd have to pass in a bunch of other variables to have access. It might make sense if you had a second (separate) class to pass the Form1 object into it to have access to all of its elements but beyond that it could get complicated.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you be more specific about what's wrong? Line 22 for example is an error -- you don't need the equals sign.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I got the same error. I went to look for that file by hand but it doesn't seem to be there. There's a note in one of the logs http://www.fltk.org/articles.php?L982 that this class was renamed so it's probably causing problems. You may have to update the CMake lists by hand but I have never done that myself. I didn't try it but the latest 1.1.x (stable) releases should have less issues.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I also just ran across this on www.cmake.org, I don't know if it's pertinent:

Visual Studio 2010 Express: Visual Studio 2010 Express came out after we made the release of 2.8.1. There is an issue with the way the IDE executable was found in 2.8.1 that will prevent projects from being created. To fix this issue, Modules/CMakeVS10FindMake.cmake needs to be replaced after you run the installer. It should be replaced with this file: CMakeVS10FindMake.cmake

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

it has entries for Visual Studio 10 (i think the same as 2010), which works on the Express Editions:

Yeah, I just went back and checked it's at the front of the list instead of at the end. Apologies.

Which version of the source did you download, I'll try it out.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What was the error in CMake? There may have been some component missing that you needed. Also, the CMake 2.8 (EDIT: Seems to be the most current) only has entries for MS compilers up to VC++ 2008 which may also be a problem. VC++ 2008 Express is still available I think. I don't know for sure but you could probably compile them on 2008 and use them in 2010.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

MouseEventArgs::Empty is of type System::EventArgs^ so you must use a dynamic_cast<MouseEventArgs^>(MouseEventArgs::Empty) to get it into the right form. However, with sending in an empty eventargs you won't have any information to provide to your MouseUp event. Perhaps there is some other way to evoke this, like having a private member method that you call from both the event handler and in lieu of calling radioButton6_MouseUp .

Also, on the first one you should use button257->PerformClick() instead of button257_Click .

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

For that question, I'd start here : http://www.daniweb.com/forums/forum4.html

However, I'd ask why you would want to use such an old language?

Next time this happens just hit the Flag Bad Post button to get it moved rather than having the OP repost the same question (not to speak for mods but I think that's the preferred procedure)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Which compiler are you using?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

f1.eof() is a method and needs the parentheses. I know with text files that using .eof() can read the last line of the file twice, but I'm not sure how it behaves with binary.

You're missing a parens on 196 also.

Look at line 221 again, check() would have to be a static method for that to work.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The delimiter needs to be a character not a string, so try putting ':' instead of ":" on line 36.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It doesn't seem as if you've included <iostream> for cin and cout. Even after including that you will also need to qualify the names. You can do this one of three ways.
First, qualify as std::cin and std::cout at each use of cin/cout, or alternatively use the statement using namespace std; at the top of your code, or lastly (as a compromise) you could put using std::cout; and using std::cin; at the top just to qualify those two names only.

Also, these are a bad idea:

gets()  //will not limit the number of characters you can enter, you can go way over the end of your char arrays into other memory
fflush(stdin); //undefined behavior, meant to be used with stdout
goto //reform your code into loops if you want this behavior
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

A couple of more things

3) It would be nice to be able to specify the number of posts per page. Sometimes it would be convenient to display 30 posts on one page so I can scroll up and down to follow long conversations
Dave

Control Panel/Edit Options/Thread Display Options/Number of posts to show per page. Dani just heard your request and coded it right up for ya. ;)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Is it just this "Receive Occassional Email from DaniWeb"? If so, then that is exactly my point! It doesn't say anything about DaniWeb Digest!
Dave

Yes. Well now you know, pass it on! :D

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Dani, Davey -
I actually haven't been able to find how/where to sign up for the DaniWeb Digest. (granted I haven't looked TOO hard). I would suggest putting it somewhere more prominently so more people sign up!

Dave

In user control panel, go to (Left Side)Settings and Options/Edit Options/(Main part of the window) Messaging and Notification/Receive Email

I think most people are signed up for it by default.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

2) On sites like (or based on) stackoverflow, there is the ability to mark a response as the "answer". This is very helpful.

As the theme from "The Spy Who Loved Me" states: "Nobody does it better..." but I do like the feature David was describing. I prefer the MSDN approach where any user can propose a post as an answer and the OP can okay it or after a period of time a mod can mark it as solved with the proposed solution. As an aside, on more than one occasion I've wanted to up or down vote a post on MSDN even though they have no such feature. :D