Freaky_Chris 299 Master Poster

There are MANY problems with you code i'm just gonna post a few to get you started with something to sort out.

My first comment is that you should be using #include <ctime> rather than time.h

number 2:

char* getMessage(const int messageId)
{
    return messages[messageId].c_str();
}

You have not defined messages...i suggest you do something about that.

number 3:

string theArray[2];
	theArray[3] = END_OF_ARRAY;

theArray[3] doesn't exsist...yu declare and array of size 2 giving you elements 0..1 then you try and access number 3...not possible its an out of range error and is not safe.
Since his is a double problem here is part 2. END_OF_ARRAY is no definded within this scope thus you cannot use it here.

number 4:

for(c = 4; c <=100; c++)
	{
	    srand((unsigned)time(NULL));        // Set a seed for random-num Generator.
		a = (rand() % 100) +1;
	}

You only need to seed rand() once in your program not 97 times. Also what is the point in generating 97 random numbers when it is only the final one that you will actually use!

And last one is not so much a problem just will help you and everyone else understand what is going on.
Use good descriptive variables names...rather than things like a b c str1 which mean nothing to anybody.

Chris

Freaky_Chris 299 Master Poster

Note there is also no such thing as this #include<stdio>
it should be csdtio....
but you can ditch that if you change getch() to cin.get()

Please don't blame a compiler/IDE for your mistakes.

By the way Dev-Cpp is dead IDE. It's advised you swap to Visual C++ (express 2008 its free) or Code::Blocks

Chris

Freaky_Chris 299 Master Poster

This is not a C++ programming question. It's an ontroduction...Try posting in the correct lobby next time.

In this case that would of been the community introductions

Chris

Freaky_Chris 299 Master Poster

Then it should be

ifstream myFile("rawDictionary2");

So it is actually a file object rather than a string object!

Chris

Freaky_Chris 299 Master Poster

i believe i told you that it is because you are declairing variables in the function call......

Freaky_Chris 299 Master Poster

Other than the fact there is no case 1, then i dont think so....plus im not to sure what case 'ID' is suppose to be...in fact i have no idea.

Chris

Freaky_Chris 299 Master Poster

Thats because you are declaring variables in the function call....
Chris

Freaky_Chris 299 Master Poster

If you want us to comment on your sort code, simple past the sort code and thats it.

this is the pseudocode for a bubble sort

procedure bubbleSort( A : list of sortable items ) defined as:
  do
    swapped := false
    for each i in 0 to length(A) - 2 inclusive do:
      if A[ i ] > A[ i + 1 ] then
        swap( A[ i ], A[ i + 1 ] )
        swapped := true
      end if
    end for
  while swapped
end procedure

Compare it with what you have does it look right to you?

The other suggestion was a selection sort
Perhaps that will help you along.

Chris

Freaky_Chris 299 Master Poster

Thats because total is never initialized to 0. So you start with a random number from somewhere in the CPU's memory then start incrementing it by 1. This is bad! very bad!

Chris

Freaky_Chris 299 Master Poster

Please use code tags, [code=cplusplus] [/code] also please try to post a specific question. We will not just do the rest of your project for you. You need to actually hve a problem before we can answer it.

Chris

Freaky_Chris 299 Master Poster

Please use code tags.
Secondly, avoid goto statements, there are much better ways of achieving the same results. http://www.cprogramming.com/tutorial/goto.html

Secondly there is no word[30] to word[299], they don't exsist so thats a very bad move to make. Also if the character matches or not you still go back and read a new line from your inputfile.

There are probably many more things i could comment on but im not going to for now at least.

Chris

Freaky_Chris 299 Master Poster

Something like daniweb is a forum mainly, i doubt you will make your own forum more just build of a forum host, try googling Forum Hosting it should turn up some good results.

Chris

Freaky_Chris 299 Master Poster

A homepage for a website?
If so you should look into HTML/XHTML aswell as things like PHP Javascript...You may find this site helpful
http://www.w3schools.com/

p.s if this guess was right your in the wrong forum :D

If not a website i'm confused by your question.

Chris

Freaky_Chris 299 Master Poster

Rather than me explaining it, i'll give you something to look at and think about. try adding the following line into your code, just inside the second foor loop

cout << "D: " << d << " B: " << b << " (" << d+b << ")" << endl;

The go through the output and see how many add up to 4

Chris

StuXYZ commented: Elegant way of getting the org. poster to think! +2
Freaky_Chris 299 Master Poster

Please don't tag other questions onto the end of exsisting threads.
If the original problem is solved please mark this thread as solved and start a new topic (if nessasery).
This is probably the best:
http://www.microsoft.com/express/download/#webInstall
Mircosoft's Visual C++ Express 2008 (if your on windows)

Or you could use Code::Blocks
http://www.codeblocks.org/

Thanks,
Chris

Freaky_Chris 299 Master Poster

Indeed, the more time you put into writing your question. Making it clear and clean. The better laid out and grammatically correct, the faster and more accurate your reply will be. Just remember that, the more time you put in the more of others time you get back. It's simple and true.

Chris

Freaky_Chris 299 Master Poster

please use code tags, and avoid red text many people will be repelled by it!

define IS_STRING 1
define IS_CHARACTER 2
define IS_INTEGER 3
define IS_FLOAT 4

This is to make a it easy for you to understand, basically writing IS_STRING is exactly the same as writing 1.

bool DotReached=false;

Create a boolean value can have the value of true or false

if(Input.length()==1 && (Input[0]>'9' || Input[0]<'0'))

Checks to see if the input is only one char long, if so checks thats its bewteen 0 and 9. Otherwise it must be a Char, cannot be a floating point. If it is between 0 and 9 then it is a integer.

if((Input[x]>'9' || Input[x]<'0') && Input[x]!='.')
{input_type=IS_STRING; break;}

Checks to see if the character is between 0-9 or is a '.' if not then its a string and breaks the loop since we have no reason to carry on.

{if(!DotReached) DotReached=ture; else
{input_type=IS_STRING; break;}

Checks to see if Dotreached has been set, if it has and we are at this point again then we know its a string. If it hasn't then it could still be a floating point.

Chris

ninja_gs commented: Thk Yu Chris........U r Kind Enough to teach me.......I m Happy ....... +1
Freaky_Chris 299 Master Poster

You have some very confusing idea's here.

Some of which are potentially dangerous.

for (int q=1; q > argc; q++){
        a.open(argv[q]);
}

What do you hope to achieve with this?
Firstly if q ever was greater than argc then you would be stuck in an infinate loop, trying to open a files with a random name, i.e one matching what ever happens to be in some memory address somewhere. Since if argc == 0 that means argv has no data stored within it. So i suggest you scrap that. Also you would only have the final file opened open, just a note.

Secondly

for (int j=1; j > argc; j++){
        a.close(argv[j]);                                 //third and fourth
    }

You cannot close files like this. a is a file object pointing to a single file. so you close it using a.close(). The method you called doesn't exsist, and once again this is also another case of...if this ever becomes true your in an infinate loop.

I think you should read about file handeling, also i cannot see the point in opening and closing files btw.

Third

for (int k=2; k > argc; k++){
        answer += argv[k];                           //second error
    }

Another case of infinate loop possibilities whilst accessing random memory!

You should really look over your code.

Chris

Freaky_Chris 299 Master Poster
Freaky_Chris 299 Master Poster

My advice, do not use eof() it's counter productive. Instead do this.

while(getline(file, someString)){
//yourcode
}

Chris

iamthwee commented: Amen +17
Freaky_Chris 299 Master Poster

MS Visual C++ Express 2008
Dev C++

VC++ is a good idea, Dev-Cpp is a dead project don't bother. Instead you could try codeblocks

Chris

Freaky_Chris 299 Master Poster

If thast all mark as solved please

Chris

Freaky_Chris 299 Master Poster

You should double backslash \\

Chris

Freaky_Chris 299 Master Poster

I strongly adivse you use code tags [code=c] [/code] Also this looks like C code to me...

So perhaps you should post in the C forum.

Chris

Freaky_Chris 299 Master Poster

Welcome to DaniWeb StainlessSteelR?
Or are you just taking the code he happened to past and chaning it and still not reading the thread.... I'm not too sure.

Anyways I think you will find this most interesting. It solves your problem multiple times.

http://www.daniweb.com/forums/thread161095.html

For almost identical code!

Chris

Freaky_Chris 299 Master Poster

There's a stray bracket in your while loop, also i think you should be using doubles not ints...

Chris

Freaky_Chris 299 Master Poster

Trying writing it out and posting it in code tags, so it keeps indenting until then it's almost unreadable.

And i would be guesing way to much

Chris

Freaky_Chris 299 Master Poster

There are alot of people that ask about card games and black jack on these forums. Why don't you search the forum and have a look over other threads solving common problems...also you can look at some example code to help you.

Chris

Freaky_Chris 299 Master Poster

Make the delay bigger, thats the idea behind wx.media.MEDIA_LOADED event it triggers when the media is loaded and only then, unfortunately it seems poorly documented.

Chris

Freaky_Chris 299 Master Poster

You need to learn to debug yourself. use print statements so you can just exactly when it crashed. Use a debugger :shock: step through it line by line until it crashes. Also is the C++ or C?

and from now on NEVER user void main() always use int main() and return 0;

Chris

Freaky_Chris 299 Master Poster

It's ok, if thats everything mark as solved please

Chris

Freaky_Chris 299 Master Poster

i may have over complicated it for you :lol: my apologise. Ofcourse this is depending on whether or not you have the array in the class as private or public. if it is private then ok you need to go down the operator route, if its public then you can use class.arrayname[][] as normal.

Freaky_Chris 299 Master Poster

Oh my bad, in that case...have a broswer through these and see which you see fit. Then try and write the code.

http://www.cplusplus.com/reference/clibrary/cstring/

Chris

Freaky_Chris 299 Master Poster

Use a couple of substrings to get the IP address since you know its always going to say, Current IP Address: you can use find to find that string, it will return the position in the string of the first character, you can then add 20 to that to give you the position of the space before the first number in the ip address, then use find again to get the first occurence of '<' from the position you have aquried from the first find. And finally use the to positions to get yourself a substring of the ip address

Chris

Freaky_Chris 299 Master Poster

You need to look into operators,
You may find this useful
http://www.cs.caltech.edu/courses/cs11/material/cpp/donnie/cpp-ops.html

Chris

StuXYZ commented: Excellent link! +1
Freaky_Chris 299 Master Poster

My first thoughts are, why have you dragged an 11 month old thread up! My next thoughs are:

Standards do NOT state that argv[0] is the filename. However it is considered good practice to make this the case. So if you are after true portability then you cannot rely on it. It is down to the OS whether or not the first argument passed is the filename. You may find that some even pass the path of the exectuable...making it even more unstandardized!

chris

Freaky_Chris 299 Master Poster

The two previous posters are correct, just a note although the logic behind it is not too hard, i would suggested you go over the manual method on paper so you know for sure what you are doing before you start writting some code. Otherwise you may get even more confused.

Chris

Freaky_Chris 299 Master Poster

OK, here is my sugestion...please bare in mind i know nothing about Python GUI and event handling so i cannot really provide any sort of code examples.

You need to ensure that the media has loaded correctly before you can play it. So the best way to doing this is to play the sound inside the wx.media.EVT_MEDIA_LOADED event.

Hope that makes sense to you
Chris

Freaky_Chris 299 Master Poster

Well generally, you will always have the ability of a loss. Even the computer defined AI will screw up alot of times. To make it so that it will always win or always draw are almost impossible. There will always be a chance that the Human Opponent will win, wether by chance or knowledge, there is always the possibility of that.

This is most certainely incorrect. It is possible to either win or draw every time. As a matter of fact not too long ago A member of PFO set up and online bot vs bot tic tac toe game to challenge AI coding skills of the locals. I believe Sane leaves his bot competing on the servers all of the time. It allows you to program your AI in several languages after it was re written by a bunch of different people. You can download all of the DIfferent API and use this as a method to write some AI that will always win / draw. Since Sane's AI is perfect you will never beat him, but if you get to a point here you never lose then you are sorted!

Here is a link to the page that contains all the information
http://www.programmingforums.org/showthread.php?t=15451&highlight=Tic-Tac-Toe

Also some very helpful links on how to always win or draw a game of tic tac toe.

http://ostermiller.org/tictactoeexpert.html
http://en.wikipedia.org/wiki/Tic-Tac-Toe
http://www.mathrec.org/old/2002jan/solutions.html

Chris

Freaky_Chris 299 Master Poster

You have to do some manual searching and it is operating system specific.

For windows you might wanted to take a look on msdn. You should find these links helpful.
http://msdn.microsoft.com/en-us/library/aa364418(VS.85).aspx
http://msdn.microsoft.com/en-us/library/aa365527(VS.85).aspx
http://msdn.microsoft.com/en-us/library/aa364232(VS.85).aspx

Chris

Freaky_Chris 299 Master Poster

What he is saying is you cannot create an array of size N like that. Arrays are constant and cannot.

he suggested the use of vectors, which can be any size and you dynamically add to them!

The other option would be a dynamically assigned array... an example of what you are after is below. Please note the delete statement is VERY important. The last thing you want it a memory leak...this is why vectors may be better if you don't know what your doing with memory allocation and deallocation.

int *x;
int n;
    
cout << "Enter a number\n>>";
cin >> n;
    
x = new int[n];
// your code here
delete []x; //always call when you will not be using the array anymore

below is an example of how to use a vector(the basics)

#include <vector>
...
std::vector<int> v;
int n;
    
std::cout << "Enter a number\n>>";
std::cin >> n;
    
for(int i = 0; i < n; i++){
        v.push_back(i);
}
    
for(int i = 0; i < n; i++){
        std::cout << v.at(i); //or v[i] if that it is easier for you
}

http://www.cplusplus.com/doc/tutorial/dynamic.html
http://www.cplusplus.com/reference/stl/vector/
Chris

Freaky_Chris 299 Master Poster

Indeed, this statement is like a an if statment its equivelent would look something like this.

string myIF(int a){
    if(a > 0){
        return ", ";
    }else{
        return " ";
    }
}

Hope that makes sense
Chris

sid78669 commented: Superbly Explained!! +1
Freaky_Chris 299 Master Poster

Thanks Chris, that did the trick! Much appreciated!
Dumb C++ 101 question... why is it so terrible that main() doesn't return an int?

Don't knock aside ArkM's suggestion of pass by refrence. It's probably the best method. Cuts out alot of stuff.

Also if you have no further question please mark as solved

Thanks,
Chris

Freaky_Chris 299 Master Poster

DOS != UNIX therefore they are different. Therefor they need different sockets. *Win*sock is the windows socket libraries, implemented with Win32 API calls, which CAn be used with DOS console applications but NOT unix.

Chris

Freaky_Chris 299 Master Poster

Mark as solved please

Chris

Freaky_Chris 299 Master Poster

I'm not entirely sure what you mean by shared object, however i'm gonna have a stab in the dark :P

http://www.cplusplus.com/doc/tutorial/polymorphism.html

Chris

Freaky_Chris 299 Master Poster

Here this link might help you out if you already know C++ and your just a bit rusty

http://www.cppreference.com/wiki/
Brilliant refrence also
http://www.cplusplus.com/reference/
has some nice stuff on it

Chris

Freaky_Chris 299 Master Poster

You can still use the windows API in your console application. There is no standard sockets implementation. So you need to use API calls, be it Win32 or POSIX.

Chris

Freaky_Chris 299 Master Poster

guesssheet[y] = s in your if statement it should be ==
You are trying to set it equal to rather than comparing

Chris

Freaky_Chris 299 Master Poster

you will need to do some form of string parsing. Firstly you need to read from the file you can use the following method

ifstream f("savefile1.txt", ios::in, ios::binary);
string line;

getline(f, line);

once you have something to work with then you can begin parsing the string.
string streams useful here,

#include <sstream>
...
ostringstream streams;
streams.str(line);
string words[3];
streams >> words[1] >> words[2] >> words[3];

That way word[1] would be "y" word[2] would be "=" and word[3] the variable.

Another method would be to read the file word by word using the >> operator.

Chris