jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Right, no I understand what you are doing, but the way you are going about it is incorrect. If _selectedName has any text in it, it messes up the int::Parse. That's why I'm asking what is in _selectedName at line 8? If it's "23 BobJones" it's not going to work, you'll have to take the substring with just "23" in it for the number to be parsed properly. If the number is not parsed properly, all of your indexes in lines 14,17,etc. are invalid, unfortunately.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See http://en.wikipedia.org/wiki/Stdlib.h#NULL as to some of the variants and rationale.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

As Jonsca said,

There should be a button to insert that phrase in the advanced editor.

Also, @OP, main is always int, never void, according to the standard. Even if your compiler takes it, it shouldn't.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

http://beej.us/guide/bgnet/ is one of the most referenced sources. I've never used it, so no guarantees. Other than that, make sure your fundamentals are sound before delving into the network programming. Have you worked in other languages before?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

after deleteing I want to show the array contents........

That doesn't make one bit of sense. Also, why are you trying to delete the array multiple times, delete [] array; takes care of it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, I forgot about that 0 3 thing. Read the line into a temp and extract the digits

char temp[3];
inFile.getline(PetID[counter].breed, 20);
inFile.getline(temp, 4);
PetID[counter].age = function to change temp to an int //check that this works for all of your cases
//like what does it look like if the pet is 14?  1  4  or 014?
inFilegetline(PetID[counter].colour, 20);
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hover over _selectedName, not firstName, there's something in the string that can't be converted to an integer.

All else fails, put in a line System::Diagnostics::Debug.WriteLine(_selectedName+" STRING"); and read what it says in the output window of the IDE.

Also, just as a side note, you can prevent this by using int::TryParse instead, it will return a value of false instead of throwing an exception.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Why do you have the '/0's on 56 and 59? I'm not sure that's it, though. Try declaring counter local to your loop instead of global. for(int counter = 0;etc.) Print out counter to see how far you get in the list when you're reading.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you know you have 100 records, get rid of the outer while loop and just use the for loop.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I've declared it as a string,

" String^ _selectedName = lstName->Items[myIndex]->ToString(); "

But what is the value of it? Mouse over it during the crash and it should tell you.

I don't know what was up with that other poster...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Any for loop can be transformed into a while loop:

for(int i = 0;i<max;i++)
{
   //stuff
}

is equivalent to

int i = 0;
while(i<max)
{
   //stuff
   i++;
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

what's the value of _selectedName at that point?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yeah, reading that character is probably throwing everything off.

with printing the records, is the commented section along the correct lines?

Yes, looks okay. cout can handle the C-string.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Resetting your counter to 10 at the bottom of the counter will cause it to run forever if you can't find the item, I'm not sure what you're trying to do there.

I would copy/paste all of your code into a separate file and strip out all of the output code in that loop until you get the input working the way you want it to, then add it back in.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That version of getline needs a streamsize, so for example inFile.getline( PetID[counter].status, ' \n '); should be inFile.getline( PetID[counter].status,6, ' \n '); (6 being the size of the status array) and really you can leave off the '\n' as that is the default.

You're not taking in the phone number in your input loop at all.

Also, why are you reading a character before reading the status?

The best test of all this is to do exactly what you planned to do in the comment section, print the records out (though probably 3-4 initially instead of all 100).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I believe he's referring to the video on the page he linked to, not the link itself.

Palm2Face() sorry totally missed what he meant!

To answer the question:[youtube]HEheh1BH34Q[/youtube] is what he used (for reference:hitting reply to on his post quotes his message directly so you can see all of his tags, then just hit the back button to escape).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What is the desired behavior on #3? If you type the link in plain text, it will be parsed into the abbreviated form like that automatically.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
string arr[] = {"step","through","the","array"}; //obviously your array will be whatever you loaded up in the loop
for (int i = 0;i<4;i++)
{
   //do something with arr[i] here
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's under Web Development, Databases. :)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Did you try the method that was outlined in the blog post? I can't recall the resolution for the functions in time.h, but it's pretty coarse.

Test what you have with something that is known (wrap your timing around a bunch of math functions in a loop and repeat them thousands of times) and see if you can register anything.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, by magic the pseudocode will be translated into C++ by your pseudocode->C++ translator. :icon_rolleyes: The idea was to look at the pseudocode and get some ideas, not blindly copy and paste it in.

No one is going to do this for you. For your p-code to work, you'll need to separate your function out into a function named f (which takes a parameter x), and of course change the loop into actual C++.

Also, please use code tags when posting your code [code] //code goes here [/code]

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The wikipedia page on that topic is great. There's an entire example in pseudocode (http://en.wikipedia.org/wiki/Bisection_method#Pseudo-code -- aside from minimal comments, it's all in function style names, so it should be understandable) and the diagram at the top is helpful. See how far you can get off of that.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I hope this Mhaoti completions with me

I appreciate the fact that English is not your first language, but I have no idea what you are trying to say there.

So what are you trying to do with this function? Take the integral of it?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm sure people will come up with other methods that are better (or better suited for the situation), but look at http://cplus.about.com/od/howtodothingsi2/a/timing.htm at least for a reference as to some of the issues, and perhaps how to get a little more resolution out of the timer, YMMV.

One thing that will help for sure is to run your algorithm through multiple times and get the total time and divide by the number of passes to get an average.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

As I said before:

double a = 1.3; //everything up to 1.9999999etc. will give you 1
int i = a;
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can't use the modulus on doubles, there is a function called fmod for that, but I don't know if that's going to get you any further along. Let the thread sit for a bit and see if someone remembers something I'm missing.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm not quite sure how to frame it in a way that it will be acceptable to your instructor.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

i cant use these method

I suppose you could just assign the double value to an int, but the cast makes your intentions much clearer.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use a cast?
C++ style:

double a = 1.40;
int x = static_cast<int>(a);

"C style" (still valid)

double a = 1.40;
int x = (int)a;

You will lose all digits after the decimal and it doesn't round, just truncates.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The whole idea of writing the strings into the array was that you could scan through the set of strings for your substring after you had read all of the strings in. Do only the scanning within the loop.

Move 17 outside of the loop (it can even go before the while loop if you want).

Also move line 18 out, but change it to step through your string array (hint: a loop will be necessary) and print out the strings that match.

I've nudged you along here, but you need to be able to do some of your own debugging. If the code isn't doing what you want it to, put some statements in there to output your variables at intermediate points to see what's going on -- or use a debugger.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You don't have a function anything like the one in your requirement.

Main always returns an int, and certainly does not take your struct as an argument. I said create an instance of your struct in main.

You don't have to use "struct" in the line struct rectinfo *p=0; , it is required in C but not in C++.

Also note that you're trying to write values into a null pointer when you say p->height = 6; etc.

Also, please use code tags [code] //code goes here [/code].

Honestly, I'd say read over whatever resources you have, and start over again with it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use new to create a pointer to a structure in main

rectinfo * rinfo = new rectinfo;

then just pass it in.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're closer, you want to put the string into the array only when the user has pressed enter:

if (c == '\n')
{
   //add str to the array
   //clear out str for the next line
   //increment i
}
else
   str+=Char;  //if we haven't hit a newline, keep adding.

You tested whether your code is working, but you also need to be able to see what's wrong.

Then, after the loop is complete, search your way through the string array and see if you find your substring. If so, print out the entire line.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See if you can do what I suggested, take each line from the user and put it in an array of strings. Don't worry about the other stuff, that's just a small step if you have the strings.

So, read character by character into a single string, once you hit a newline, copy that single string into your array of strings.

Make sure you change the type of your variable "Char" to be an int, as that's the only way it's going to work out with EOF.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Read in the lines one by one and write out the ones you want to keep into a new file. Please post what you have tried so far.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Why are you trying to output your string on line 29? If you haven't found the substring that you've supplied, just throw it away.

Also, note that you are getting a new character on lines 17,24 and 28, which you should only get one character once through the loop (on line 13)

How do you do that?

//early on
int i=0;
string arr[10]; 
//later in the program
arr[i] = str;
i++;

Edit: To get the EOF to work properly, instruct your users to hit enter at the end of the last line, do the ctrl-z, then hit enter.

Another hint, start a fresh program, and try at first to get the lines and simply output them. Then you can add in the other functionality later.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

#include <cstdio> which is the C++ version of the stdio.h header.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No prob, lol. I had to look through it once more to trace it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You don't check if the day is negative in minusOneDay at all. You do it in addDays, but that's it, and those two methods don't interact. So when day = 0 (Monday), in minusOneDay you subtract 1 (= -1) and pass it into toName which can't handle the -1. So, do some range checking on idx in toName.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, I see that you did it in the other function. Post up your current code that you are working with.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

how to passs strutre to an arry

Aside from having to strain my eyes to read that, what do you mean? How to make an array of structs?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

So check if your number is negative, and if it is, add 7 to it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Part of the reason you're getting numbers is that cin.get() returns an int (it has to because it can return EOF, which is normally a negative number). So "Char" the variable should be an int. I've run into a problem which I always hate, in that you have to hit EOF (ctrl-z on Windows, and ctrl-d on *nix) twice to get it to work.

The other element I think you need to get it to work is to use an array of strings to hold the lines as they came in. That way you can print them at the end. I was trying to help you print them after they were entered but I don't think that's what your specification wants.

Check around for some other examples related to this, give it some more shots, and see what you come up with.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Dude, no one is holding you captive here, the site will be fine, thanks.

It's "little to no", by the way.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
while((Char = cin.get())!=EOF)

This is getting Char (consider changing that name as it's rife with possibilities for typing in "char" by mistake) as an integer so it can be compared with EOF. You will probably need to cast it to a char before you tack it onto str.

Why are you outputting found? found is only going to give you the position in the string. Do what your originally specified, if found is true, output the whole string, otherwise clear the string out for the next line. If you don't clear str out, you're going to end up with everything you've ever input in it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You'll have to shift your while loop around to encompass the information that was in your for loop

while(not at the end of the file, read in a char)
{
   if that char is not '\n'
       add it to the string
   else
       //line is done
       check to see if the substring is in the string
       if(so)
           print it out
       else
           clear the string and continue on
}
Saith commented: Nice pseudocode +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Why do you need the loop on line 19? argv[0] just contains the name of the executable. If you want the last argument go to argv[argc-1] .

This is where I was saying that you should read into str up until you hit a '\n', then do your find(), print it out if the substring is in there, then clear out str for the next line.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I would read the data in as a std::string using getline and go through character by character (or using datain.get() to read the file in character by character) rather than dealing with doubles (especially if there are +/- and other characters thrown into the mix). You can use the functions in <cctype> to figure out if the characters are numbers, or simply use something like

char c = 'd';
if((c >= 'a' && c <='z') || (c >='A' && c <='Z')|| etc.)
    //etc.
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I understand your requirement. I'm saying that rather than weeding through 500 lines of code, it would be preferable for you to say "On line X of function Z, I want to be able to enter Y, but the line fails to execute" rather than "here's my requirement."

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Gotcha.

I'm assuming you're not allowed to use getline. I would read until you hit a '\n' and check the line. If it contains the substring, print it right out. If not, clear the string and start again.

Did you look up how to get arguments from the command line?