jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you have an array of characters |1|2|3|4|5|\0| you know the third character (at index 2) is always going to be the same, so compare indexes 0 and 4 along with indexes 1 and 3. If the number of matches is equal to 2, they are the same. This may seem more tedious to do, but try using your method on a 1000 digit number.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I was thinking more along the lines of the following for input

char number[6];
fgets(number,6,stdin);

Theoretically yours works, but look at the third line and the number is being printed out in the same order. I suppose the comparisons don't take any more work your way.

You'll have to watch that you put in the commas, though, as that's what your scanf is calling for.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hint: get the user's input in the form of a char array (use fgets to read the line of text).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

no file gets created

I've never used a Tinifile. From the syntax of the subsequent statements it seems like you're trying to read from it rather than write to it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use a boolean variable to distinguish whether the program has passed the empty line in the file. Once the line has past, reset the counter. If the statement about passing the empty line is false, write into the first array. If it's true, write into the second array. What you have works, so if you don't need the extra headache right now, I wouldn't worry about it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Seems perfectly reasonable. You could eliminate some of the duplicate code by detecting whether a line with a space has been read (or if the leading "up" has changed to a "uq") to separate the two, but that's just window dressing.

If there's any flexibility in the data file configuration, you may need to adapt your code to account for that (splitting the string on spaces and equals signs like I had originally suggested.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Are they std::strings? You can use the string's find method (http://www.cplusplus.com/reference/string/string/find/) to locate the string "\n\n" (using multiple calls to it, noting the position at which you last found it as the beginning of the next search).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm not upset, it's just that it's your assignment, so you need to put in some effort on it.

Are the points for each of the shapes together? (sh1 = shape1, p1 = point1)

sh1_p1
sh1_p2
sh1_p3

sh2_p1
sh2_p2
sh2_p3

or are they intermingled

sh1_p1
sh2_p1
sh1_p2
sh2_p2

If it's the former, there should be some delineation between the two sets, so scan until you hit that (if it's a blank line check for s == ""). Then start another while loop where you left off (the ifstream will keep track of where you are).

If it's the latter you could do something like

string s1;
string s2;

while(getline(pts,s1))  //advances the file one line
{
   //process s1 for first list
   
   getline(pts,s2); //advances the file another line
   
   //process s2 for the second list
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That sounds like the meat of your assignment. I will not be able to take you through the entire thing step by step. Give it a try on your own now that you have some of the basics covered. If permitted, post your code attempt and someone can take a look at it for you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Right, so you want your substring to start at 20.

You should compile it and check, though.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can access the x and y of the ipcounter-th point by pt[ipcounter].x and pt[ipcounter].y substitute those in on lines 35 and 38.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Line 28 should be eliminated.

You will probably want to declare an array of points (or a vector if you don't know how many you will have) somewhere around line 20 or wherever it makes sense.

In this example, as long as you have declared a point pt, you can use pt.x and pt.y anyplace you would ordinarily use a double.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No, apologies. It's either one or the other. Presumably you'll want an array of points, so you can incorporate the code into your while loop and increment an index to keep track of where you are in the points array.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to use the .c_str() method of your strings to get their C-string representation:

point pt;
pt.x = atof(xcor.c_str());
//etc.
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Are your numbers guaranteed to be a fixed number of digits? If not, you'll have to do the splitting like I was saying.

For the way you have it:

point pt;
stringstream ss(xcor); //set up a stringstream with the first string
ss >> pt.x;  //extract the number
ss.clear();  //reset the stream to the beginning
ss.str(ycor); //set the stringtream to the second string
ss >> pt.y;  //extract the second number

be sure to #include <sstream> Something like atof is also a possibility if you wanted to go that route.

Put your getline statement in the while loop to drive it rather than using .eof() (which can read the last line twice in some cases)

while(getline(pts,s))
{
}

Also, main is never void, it always returns an int according to the standard.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Read a line in the file into a std::string with getline() and then parse that string with a stringstream.

I'm not sure it's the most efficient way to do it, but to start, break it in half on the space, then read the halves up until ':' and throw that part away, then read in the numbers.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Here's a good (but not great reference/tutorial) http://www.functionx.com/vccli/index.htm

If you know what you need MSDN is the best place to find class definitions, etc.

The beauty (or some would say the bane) of .NET is that you don't have to do anything when the user clicks the X, all of that is taken care of. Now if you want something to happen when you click the X (besides the program exiting) you have to add some code to the event handler. With the Form1.h [Design] tab selected, click on your form, go over to the properties pane on the right side of the VC++ window, click on the lightning bolt, scroll down to form closing and double click the cell right next to it. That will place the even handler in your code. Check out http://msdn.microsoft.com/en-us/library/system.windows.forms.form.closing.aspx for the specifics.

Any references you find with code for .NET that are in C# can be translated to C++, knowing that in C# the . operator serves as both namespace separator and as method invocation.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

the security will not be an issue

I'm no expert on the topic, so this is just a thought, but what happens if one of your trusted users has a weak password and the account is compromised?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I don't know if it would suit your project, but what if you had two arrow buttons in between your text boxes:

________________          _______________
|     1        |          |       2      |
|______________|  ->  <-  |______________|

The first arrow would convert from box 1 and place the calculated value in box 2, and the second arrow would take the value in 2 and place the calculated value in box 1. Then the circular dependency between the two wouldn't be needed. You'll probably need to have a couple of boolean values to determine whether the value in the box was freshly calculated and can be used in subsequent calculations. Again, just a suggestion.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The size of an array must be a constant known at compile time. You should dynamically allocate it char * fileTemp = new char[fileTempsize]; instead. Some compilers are able to do what you tried to do, but it's an extension and is non-standard.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It is also incredible how you manage to write 4000 lines of code and have a problem like this. Did you not test your program as you went along?

Agreed. Also, as I suggested with your other difficulty, make a "toy" program that contains only the 2 textboxes and see if you can reproduce the problem that way.

Programming all of these magic numbers into your code is also going to spell disaster if you need to change anything. See if there is another way to approach your problems (e.g., storing some of your constants that vary with other values in parallel arrays or in a list). As it is, it's going to be difficult to maintain.

You may also want to hold off until you know some information about classes and use them to consolidate your code.

kvprajapati commented: N/A +11
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
int i = 0;
    int j = 0; 
	 while([B]i <= 2[/B]){
         while(j <= 8){ grid[i][j] = 0; j++;}
         j = 0;
         i++;
    }

Why are you only going up to 2?

There's nothing wrong with the way your loop is structured, except for that index (and MasterGBerry's works fine too), but I think it's much easier to read with a for loop:

for(int i = 0;i<4;i++)
{
    for (int j =0;j<9;j++)
    {
         grid[i][j] = 0;
    }
}
//braces added for clarity
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What did your nested for loop look like?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Let's see if anyone else has some insight as to whether this is possible.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How are you getting your code from Vim to the IDE? (in other words are you opening a project for it..or?) If you're writing in Vim, you could just possibly skip the IDE and compile right from the command line.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Sorry, I had misread your initial post. Hmm. Well, since the C code belongs to you, is there anything stopping you from doing a search and replace on it. I imagine there is a way to do what you want but I'm not sure what it is.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I have a class that uses C libraries to make a TCP connection

I assumed that this meant that you had a wrapper for your C functions. If not, can you modify the TCP class?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Qualify it with the name of the TCP base class: MyTCPBaseClassName::connect()

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I was offering string input as an alternative to the "int number," but you're right based on his specifications.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

...and what's the question? This looks like C (albeit non-standard) to me.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Oh, our posts crossed. Okay, glad you got it to work!!

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think if nothing is selected the index is -1.

Oh, I thought that's what you wanted (to have the progression go by 1 each step). Ok. Well, make an array: cli::array<int> ^ pointsarr = {4,2,7,5,8,9,22}; and add pointsarray[comboBox1->SelectedItem] to your total instead.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Either read it in as a string and access the digits as characters, or get the remainders after division by 10, subtract remainder, division by 100, etc.

Please post your attempt and someone will look it over.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Oh, well, that's even easier. Just write out the RGB values as text and read them back in again.

int firstnum = 255;
//etc.
sw->WriteLine(firstNum.ToString()+" "+secondNum.ToString()+" "+thirdNum.ToString());

Read the line back in and parse the numbers out from the string to get them back.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You could write out the color as plain text and use a switch statement to get the color back again.

-or-

For an object, you need to serialize/deserialize it from a binary file (since you can't write out your color object itself as text). See http://msdn.microsoft.com/en-us/library/system.runtime.serialization.formatters.binary.binaryformatter(v=VS.100).aspx

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you have the first option selected (option 0) it returns 0 (total +12), second option (option 1) it returns 1 (total +13). Chaeldar would add a total of 12. Just make a form with a combobox on it and play around with it a little. You don't need the if statement like you have it because the box is agnostic to the actual contents, as long as you keep everything in the right order it's fine.

but does this apply to a specific option or all options in the combobox?

Every option has an index associated with it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There is one super easy way to tell what the output is. Compile and run the program.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Did you try Googling? There's plenty of code out there for this type of thing. One example, with a nice webpage to explain it. http://webdocs.cs.ualberta.ca/~lindek/hmm.htm That gives you the HMM part and you can get the camera code from OpenCV (I haven't looked under the hood of that library quite yet, but it seems like Mike is saying that a lot of their stuff is based on HMM anyway).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

For the rest I have absolutely no idea. In fact, you didn't mention from which language you are translating this code. In what programming language is the code you posted? I cannot tell and have no idea what the "=>" syntax is supposed to mean (maybe equivalent to "->" in C++, just as a guess).

The => symbols are found in lambda expressions in C#
(ex using a C# count operator int oddNumbers = numbers.Count(n => n % 2 == 1); ) n is basically an anonymous function.

All of these SelectMany() and Select() are LINQ (language integrated query) methods and you'd have to implement those by hand (doubtless that there are algorithms out there used in SQL connectors). You could probably get away with treating some of your data like a database and running similar operations from a SQL library.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You want something along these lines

int tb1value;
Int32::TryParse(textBox1->Text,tb1value); //enclose this in an if to make your own error handling
int tb2value = tb1value+comboBox1->SelectedIndex+12; 
//it doesn't matter what's in the box, just use the offset
textBox2->Text = tb2value.ToString();
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think it's Ctrl-D on those systems, actually.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Double check it, but I think it amounts to an integer division (clock_t is usually a long int and I think the constant is an integer value). Cast one or both to float.

EDIT: Edged out by the Code Goddess :)

Clinton Portis commented: muy bien +6
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There's nothing wrong with your codes. What's wrong with "Go To"?

Nothing, if it's used very judiciously, but it's awfully easy for it to make source code into a mess of spaghetti that's difficult to follow. Code readability is important.

jember commented: Thank you :) +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
gets(path1);

You can overrun your buffer with gets. Use fgets instead (or you can use cin.getline if you want to use the C++ standard library).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use Int32::TryParse instead:

int result = 0;
if(Int32::TryParse(textBox9->Text, result))
{
    //etc.
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster


KeyChar is not a member of KeyEventArgs. Do you mean KeyCode?

I thought the same thing, but for the _KeyPress event the second parameter of the method is a KeyPressEventArgs (which has the KeyChar member) instead of a KeyEventArgs

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm going to be the dissenter and say take biology. While bioinformatics isn't at the same level of popularity that it once was during the big push of the human genome project, there's still a lot of work to be done there.

Of course, if you know you have no interest in the field, then take whichever one you like the best and doesn't load you down so you can spend more time on your concentration. I've never interviewed anyone for a position, but I'd wager that which science course you took for a requirement won't even enter into the equation. Just make sure you pass! :)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Except that if the value is not found the newValue would be set to the default value for a particular type (0 for ints, false for bools, null for objects) see: http://msdn.microsoft.com/en-us/library/zkw5c9ak(v=vs.80).aspx

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I hope this will help you

No, in fact you've hurt his/her chances of learning from this because you've done it for him/her.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Are you looking for a specific ordering like 000-111-2222 ? If that's the case you might want to try a masked text box. There is a current thread in C# on this (http://www.daniweb.com/forums/post1440491.html#post1440491) (I know it's not the right language, but it's the same .NET library, so you'd just have to translate it into C++ syntax).

If that's not what you need, post back and we can help you figure out what you need.