Freaky_Chris 299 Master Poster

As you stated the advantage of auto_ptr's is the fact they deal with cleans up's automatically. Such as if an object was created with new, and delete was never called for any reason such as program terminated before delete was called for any reason. Then indeed you have a memory leak! Where as no matter what auto pointers with delete any object they are assigned too.

However one dis advantage to the auto_ptr is the fact it doesn't like to be mixed with standard containers such as verctors. Also you cannot copy* an auto_ptr as the copies created are never an exacted copy. As you can imagine thats gonna end badly for everyone!

As for method 3...i'm not sure as thats even a pointer...you simple clear any contents at its memory location using memset...

Chris

Freaky_Chris 299 Master Poster

Firstly, please don't hijack others threads...start your own in future. Your syntax error is the fact that you have a do..while loop definded as follows

do{
    //somecode
}

with no while statement

do{
    //somecode
}while(somecondition);

Chris

Freaky_Chris 299 Master Poster

There shouldn't be a problem here... i just created a simple program to open a file that contains some text in exactly the same mode as you, and called seekg(0, ios::beg) without a problem...

you could always try calling f.clear() before hand...

Chris

Freaky_Chris 299 Master Poster

Either way you are going to have to make sure you clean up all memory assignments. The bonus of new/delete over malloc/calloc/realloc/free is the fact that new and delete call constructors and destructors of classes (potentially allowing you to clean more memory up easier. This was also the reason for using new and delete (i believe) since there needed to be a way of calling constructers when allocating memory) which is a big bonus.

Other than that, as far as i am aware the only difference is synatical. Plus new doesn't require type casting!

If anybody could shed some more light on this i would also be grateful!

Chris

Freaky_Chris 299 Master Poster

Please read the links, i'm not going to do everything for you. They are clear enough. You can realte them to your code and see what is different.

If when trying to replicate one of the solution you have a problem or do not understand a function for example strcmp() then ask about it.

Chris

Freaky_Chris 299 Master Poster

This is because you need to work on sorting and searching C style strings. I think you are gonna have alot of work to do! Here's some material that might help

http://www.daniweb.com/forums/thread6713.html -- Sorting C-Style Strings

Example Code for a C-Style String binary search
http://www.c.happycodings.com/Sorting_Searching/code3.html

Chris

Freaky_Chris 299 Master Poster

Either way very very old thread, don't drag anymore up SRaj

Chris

Freaky_Chris 299 Master Poster

How are you getting this error exactly what is the code causing it?

Chris

Freaky_Chris 299 Master Poster

I did tell you the solution above, but they still wont wor either way!

You should of posted in the C forum! Rather than C++.

string object do not exsist in C, you have to use an array of chars so to speak

char *words[] = {"This", "should", "be", "in", "the", "C", "Forum"};

Chris

Freaky_Chris 299 Master Poster

im trying to show what is stored in arrays, basically to make sure my program is working fine, i have got it to print which element in the array it is, but how do u access the array and show what value is stored in it. my code is basically

for(int i = 0; i < 16; i++) 
            {
                for(int j = 0; j < 60; j++)
                {          
                    cout << endl << "string " << i << "weights " << j;  
                }
            }

i know this will only print the value of whatever j is. not what is stored in element j.

any help will be greatly appreciated?

This is most confusing, are you saying you have 2 arrays called i and j as well as using i and j as loop counters!!!! Here's an example i suggested you look through it

int age[] = {3, 67, 234, 34};
for(int i = 0; i < 4; i++) {
        cout << "Age: " << age[i] << std::endl;
}

Chris

Freaky_Chris 299 Master Poster

You need to update your functions to take string arguments rather than char's.

Also your selection sort will not work on strings, as far as i am aware.

You should be using int main(void) and return 0 !
Also are you sure that this is C++ and not C?

It certainly looks like C to me

Chris

Freaky_Chris 299 Master Poster

Please just post the code, the download doesn't work anyway.

Doesn't matter how long it is. And make sure you use [code] tags

Chris

Freaky_Chris 299 Master Poster
Salem commented: Careful, that link might be a bit advanced for them ;) +24
Freaky_Chris 299 Master Poster

I should of added its a member of the std namespace.

#include <string>
#include <iostream>

int main(void){
    
    std::string myArray[] = {"Cat", "Dog", "House"};
    
    for(int i = 0; i < sizeof(myArray)/sizeof(*myArray); i++){
            std::cout << myArray[i] << std::endl;
            }
    std::cin.get();
    return 0;
}

Chris

Freaky_Chris 299 Master Poster
#include <string>
...
string myArray[] = {"Cat", "Dog", "House"};

Hope that helps,
Chris

Freaky_Chris 299 Master Poster

Hmm, thanks for that ArkM. My thought's were pass by refrence initally but...i though he may of had a reason behind not doing that

Chris

Freaky_Chris 299 Master Poster

Thats because the stack will be empty so you need to check stack.isEmptyStack(), if its empty break out because its unbalanced, if its not empty continue on and check.

Chris

Freaky_Chris 299 Master Poster

The reason that doesn't work is because it's an incorrect method of reading what is at point i in the vector.
You should be using his method

PtrMyVector->at(i);

Also i wanna make this comment:

do NOT use void main()!!!!
use int main() and make sure you return and interger! (return 0; )

code tags are also very nice!

Chris

Freaky_Chris 299 Master Poster

Not too basd, the reason is this code here

if(exp[x] == stack.top())
{
	stack.pop();
}

This should be a comparison to the opposite of stack.top() for example you are comparing like this -> ']' == '[' which will never be true. You will need to check that the brace type is the same and is opposite to the one of the top of the stack, if thats true then pop. if it isn't true, then break out of your loop since it is unbalanced.

Chris

Freaky_Chris 299 Master Poster

This is a common problem, it seems you have to manually include the mail module, this link maybe of help to you
http://stackoverflow.com/questions/169897/how-to-package-twisted-program-with-py2exe

Also another suggestion rather than py2exe use bbfreeze
http://pypi.python.org/pypi/bbfreeze/0.95.4

Chris

Freaky_Chris 299 Master Poster

So your set and know what you are doing. Trying coding something then coming back with specific problems

Chris

Freaky_Chris 299 Master Poster

It's a link click it and read it. Here's another good one

Freaky_Chris 299 Master Poster

a) you don't need to pass arrays "by reference" with the & in c++ because they are pass by reference by default.

b) 'cout << random << "\n";' on line 65 is your problem. outputting a whole array like that doesn't work. you need to output each element separately.

oh jesus! I'm such a muppet. Thats 2 comment in 20 mins where i've said something completly stupid! I'm gonna get some sleep before i look like a complete idiot lol

Chris

Freaky_Chris 299 Master Poster

This is easy.... Count
If you get below zero then you have failed,
and if you get not-zero at the end you have failed.
You might want to check scope bridges. I.e.
(a{b+c)} which I would pass as fail.
but that is easy to modify the code below to include.

Example of pseudo code for JUST ( and ).

string A = "(expession) with ) ( ";
int b(0);
for(int i=0;i<A.length();i++)
 {
   if (A[i]=='(') b++;
   if (A[i]==')') 
     {
       b--;
       if (b<0) failed();
     }
} 

if (b!=0) failed();
success();

Additionally, I am sorry BUT you cannot use boolean values as suggested by freaky_chris since
the expression ((x+y)) would fail. And that is not acceptable.

ooh, valid point. I hadn't though about that one i do apologise...
Chris

Freaky_Chris 299 Master Poster

BOOM!

Chris

Freaky_Chris 299 Master Poster

loop throught all the elements on the stack, check what it is either ()[]{} and use 3 different boolean values, 1 for each brace type ie 1 for () 1 for [] and 1 for {}. then toggle states...if that makes sense and if the state wouldn't chage then you know they are not balanced.

That was poorly worded i think sorry :(

Chris

Freaky_Chris 299 Master Poster

Um, by wierd output do you mean un sorted. Cause i have a strange feeling (unles si missed something) that you sort (or at least try to) the array list....which is just discarded once your sort is completed.

You need to pass by refrence... using the & operator in your function declartion for list.

Chris

Freaky_Chris 299 Master Poster

our instructor wants us to use the !variable.eof() so how would I use it without messing things up? Also, I tried the .good(), and it just ran through the file once, didn't actually loop. Second, I used a debugger, it came back with no errors. Which is why I came onto here, for help. I took out the peek, nothing happened. The getline(), I will try that and see if things work better! Thanks.

I trust you have stepped through execution line by line to see the exact moment it goes to pot?

p.s tell you lecturer to stop teaching bad practise.

Chris

Freaky_Chris 299 Master Poster
this->finishToolStripMenuItem->Break = true;

I think, basically what ever the handle to the menuoption is, followed by ->break= true

Chris

Freaky_Chris 299 Master Poster
Freaky_Chris 299 Master Poster

Count your brackets

srand((P1Cards)time(0));
srand((CompCardstime(0));

Chris

Freaky_Chris 299 Master Poster

I have no idea how sorry i can't help


I'm such a kinda man......after that title

Freaky_Chris 299 Master Poster

When is the problem, unexpected out put wtc. We cannot judge what you have done incorrectly if you don't tell us how it is wrong

Chris

Freaky_Chris 299 Master Poster

you need to add the & on the function declaration and definition

Chris

Freaky_Chris 299 Master Poster

Here is one method of doing it, get the Age from the user, loop through your linked list. If you find it don't add it to the list if you don't then when add it to the list

Chris

Freaky_Chris 299 Master Poster

Use code tags please [code=cplusplus] [/code]
Also what exactly is the problem?

Chris

Freaky_Chris 299 Master Poster

Hmm quick suggestion probably a crazy one :D does this work

static void Test2(list &tester)

Freaky_Chris 299 Master Poster

Ah, so using Dev is there anyway that this can be solved? As I would hate to have to swap to VC++ just to solve this problem. Using Dev Allows me to do some stuff whilst i'm in college :D Where as i wouldn't be able to do anything if i had to use VC++ :/

I'm aware Dev is old...perhaps i should have a look at Code::blocks.

I just like Dev it suits me :P

Chris

Freaky_Chris 299 Master Poster

Hi, i'm doing some work with double atm and i have what appears to be a simple expression. When i work this out in my head i get the answer to be 0. However running the code gives me a very obscure value -5.77338e-017

Any help as to what i am doing wrong, P.S the answer i am atfer is 0

double a = 0.96;
double b = 0.9;
double com = 30.00;
std::cout << a - ((2.00*(com/1000.00)) + b);

Thanks,
Chris

Freaky_Chris 299 Master Poster

Well what idea's do you have for writing a jump function. I guess you would have to think about a couple of things, What exactly is your motion path when you jump, how the direction of movement before hand effects the mothion path of the jump. Also you would need a method of checking whether or not you have landed/collided with another object.

Chris

Freaky_Chris 299 Master Poster

Indeed, I happen to know of a rather popular Open hacking forum...i use it from time to time for some more obscure code snippets to learn from, normally things that involving working with OS dependant calls.

I don't understand why you would want to write a virus when you could put you talent* to a much more productive use.

Chris

Freaky_Chris 299 Master Poster

If you zip the file then you should be able to sen it with no problems. The other user will just need to unzip the file and then run the exe

Or you cuold go down the root of changing the extension

Chris

Freaky_Chris 299 Master Poster
Salem commented: Gotta love LMGFY :D +23
Freaky_Chris 299 Master Poster

You can just do the following

if(line[0] == '<' || line[0] ==' '){
   //some code
}

Chris

Freaky_Chris 299 Master Poster

In that case i think this is your problem

tmp = foods[j];
			foods[j] = foods[j+1];
			calories[j] = calories[j+1];
			foods[j+1] = tmp;

You need to put the value of calories[j] back into calories[j+1]

Chris

Freaky_Chris 299 Master Poster

Create a structure containing both the food and its caleries. something like this

struct food{
       string item;
       int cal;
};

Then create an array of that structure store all the value into the array ie food[0].item = "crisps" & food[0].cal = 200 etc.

Then use food.cal to do your check on etc and re order the food array so for example swap food[0] with food[1].

I hope that makes sense lol. I does in my head but i'm bad at writing things on paper

Chris

Freaky_Chris 299 Master Poster

How silly of me, Ye i was just tyrying to get it working before i set up failure checks, thanks for that. It was 2 silly mistakes. It's because i originally had it set up not using an array just to process one event and din't think to update those bits lol

Thanks,
Chris

Freaky_Chris 299 Master Poster

Hi all, i'm looking into doing a little bit of work with the mouse in console applications on windows. I'm using windows.h to get access to functions such as ReadConsoleInput. I've created a simple program that just prints a string whenever the left most mouse button is clicked. However sometimes it works fine sometimes it doesn't. By doesn't work it seems to be that when i run it if my curser is out side the console window then when i move my mouse into the console window it crashes. If it is inside to begin with then i seems to be ok....quite odd.

I was wondering if you could shed some light on where i have gone wrong thanks.

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

using namespace std;

int main(void){
    
    HANDLE stin = GetStdHandle(STD_INPUT_HANDLE);
    DWORD NumRead;
    DWORD numEvents;
    
    while(1){
              GetNumberOfConsoleInputEvents(stin, &numEvents);
              INPUT_RECORD *inputStat = new INPUT_RECORD[numEvents];
              ReadConsoleInput(stin, inputStat, 1, &NumRead);
              if(NumRead != 0){
                 for(int i = 0; i < NumRead; i++){
                    if(inputStat[i].EventType==MOUSE_EVENT){
                       if (inputStat[i].Event.MouseEvent.dwButtonState & 0x0001){
                             std::cout << "Clicked\n";
                             }
                    }
                 }
                 delete inputStat;
              }
              
         }
    
    return 0;
}

Chris

Freaky_Chris 299 Master Poster
string myString;
getline(cin, myString);

Chris

Freaky_Chris 299 Master Poster

Note you can use find() or find_first_of() etc to get the index of the character youare after.

Chris