Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The reason is there is a maximum value that an integer can hold -- the maximum is declared in the header file limits.h that is supplied by your compiler. What you are seeing is called numeric overflow.

If you need bigger numbers then use a bigger integer, such as "long long", which holds about twice as many digits as an int or long. There are no standard C or C++ data types that will hold an infinite number of digits.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

lines 173 - 194: Do not put executable code inside header files, move those two functions into a *.cpp file like GameUnit.cpp. The same goes for Player.h.

After making the above changes everything compiled ok for me. I just added two more files: GameUnit.cpp and Player.cpp

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

*head = NULL in the constructor is probably incorrect. How did you declare variable head? If something like this: char* head; then in the constructor it should be head = NULL; (note that there is no star).

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Post the entire program because the code snippet you posted compiles ok for me using vc++ 2010 express compiler/IDE.

[edit]I used the exact same code as ^^^ posted.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

No. All you have to do is initialize pointers to NULL when declared, e.g. int *ptr = NULL; or set them to NULL in c++ class constructors. There is no such test for other kinds of variables.


But you can either write your own or use an existing smart pointer c++ class. google for "c++ smart pointer" and you will find examples and tutorials.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> for (int n=0;n<=99 ;)

What makes you think there will be 99 characters in the string? You should use this: for(int n = 0; n < words.size(); ) Also not that you should use <, not <=

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I would first put something at the end of the array to indicate there is no more data -- that way the program knows when it is done. The last byte in the array could be either another $ or binary 0, but anything except numeric digits could be used too. After that, just modify the code you have to keep looping through the array's memory until end-of-array byte is found. You might want to put the code in another function then repeatedly call that function for each item in the array.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

google for "berkley socket tutorial" or "posix socket tutorial"

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

at line 29 you are setting seconds back to 0. So it's an infinite loop.
Use a different variable in for loop condition.

Oh yes, I hadn't noticed that.

The program can be greatly simplified

in main()
{
   wait(90); // wait 1 1/2 minutes
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The timer is set to run for about 90 secndxs. Why do you think it should run until 1:30 ?

>>if(seconds == 90)

Impossible. The loop will stop as soon as seconds == 90, so the statement above will never get executed.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>(*bags[0]).someReceiptBagFunction();

Or, more simply bags[0]->someReceiptBagFunction();

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why not just make the array of pointers (note that arrays of references are illegal).

ReceiptBag zero("zero");
ReceiptBag one("one");
ReceiptBag * bags[] = {&zero, &one};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why are you trying to assign an array of pointers (str) to a single string? Also you failed to heed my warning about argc. If you want to do anything useful you have to start from argv[1] to argv[argc-1], not the other way around. Western languages read from left to right, not the other way around, and that's the way they are represented in argv.

// ArgParse.cpp : Defines the entry point for the console application.
// How can you refer to a character in a string? This does not work !!!

#include "stdafx.h"

#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>

#define STRINGSIZE 128

int main(int argc, char *argv[])
{
	char ch;
	char *str;
	int c = 1;

while (c < argc) {
	printf("arg %i - |%s|\n",c,argv[c]);
	if (argv[c][0] == '-') {
		printf("|%c|\n", argv[c][0]); // then show what it is 
             // assume the option string immediately follows the - symbol
             if( stramp( &argv[c][1], "Hello" )
             {  
                 printf("%s\n", &argv[c][1]);
             }
	}
	c++;
}

system("PAUSE");
return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>c--;

The initial value of c is too large. The value of argc is the number of strings in the array. So it counts from 0 to argc-1. You should make the loop as you would when using any other array

for(int i = 0; i < argc; i++)
{
   // blabla
}

If you would rather use a while loop, then

int c = argc-1;
while( c )
{

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

LPCWSTR is a pointer to TCHAR so just use the & address operator to make the conversion
TextOut (hdc, 40,40,&chCharCode, 1);

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The first function is incorrect

void print (string word)
{
	cout << word << '\n'; // display the string
}

Now do similar for second function, but this time put cout statement inside a loop.

zeroliken commented: simple as that +8
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here's a link for MS-Windows (and it won't matter which 32-bit compiler you use. It won't work with Turbo C or Turbo C++)

DeanMSands3 commented: Rock on, Ancient Dragon. +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Another difference -- the value of const char cannot be changed but the definition of #define's can be changed. That makes const char a lot safer to use than #define's

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You have to change HowMany() so that it displays the values of the 3 parameters. And those parameters don't have to be passed by reference. void howMany(int count1, int count2, int count3)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Post your newest code.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Have you tried this?

thines01 commented: Excellent Suggestion! +12
DeanMSands3 commented: Thank you, Ancient Dragon. You've changed my life, and my forum posting career, forever. +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Your code compiled ok for me without errors or warnings using vc++ 2010 express. I just copied it all into one *.cpp file.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

i try your code already, but got error......

I'm not a mind reader so you need to tell us what the error was and post the code.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You need to use an array of ints, one for each task. Or if you know there will be only 4 tasks then you can use 4 different int counters

int count1 = 0, count2 = 0, count3= 0;
int main(){
int option =0;
bool exit = false;
while(!exit) {
displayMenu(option);

switch(option) {
case 1:
doTaskA();
count1++;
continue; 
case 2:
doTaskB();
count2++;
continue;
case 3:
doTaskC();
count3++;
continue;
case 4:
howMany(count1,count2,count3);

exit = true;
break;
default:
printf("Incorrect selection. Try again.\n");
continue;
}
}

return 0;
}
[
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>EDIT : My project is a Windows Form type.

That is not c++ -- its CLI/C++ which is slightly different language

>>This can be done more easly with the webBrowser1 from Tools ?

Probably.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> Error Msg is still there

What error message? Please post the exact wording. As I said before your program coompiled and linked ok for me without errors or warnings after I changed private: int a; to protected: int a;

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It can be also easily done with C# and VB. But since this is c++ forum ...

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Learn socket programming. How to do that will depend on the operating system you are using. If *nix you need POSIX sockets. MS-Windows use WinSocket.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is boost-html that might help you

IndianaRonaldo commented: Thanks!! I checked out that one too, but it doesn't have very good forum support, so I went with libxml2. +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>It seems like Visual Studio 2010 compiler is complaining that despite all classes are in the same namespace, the abstract class's pure abstract method is not implemented.

I think you mis-interpreted the error message -- see comment below.

This works ok for me using vc++ 2010 express. The only change I had to make was make variable a in ParentClass protected so that it can be used in derived class.

#include "IBaseClass.h"
#include "ParentClass.h"
#include "concreteClass.h"
using namespace std;





namespace MyCustomNamespace
{
    void ConcreteClass::setB(const int bb) { this->b = bb; } 
    const int ConcreteClass::getB() const { return this->a; }

    bool ConcreteClass::Method001(/*some input*/)
    {
      //implementation code goes here...
        return true;
    }
} /*NAMESPACE*/


    int main()
    {
        MyCustomNamespace::ConcreteClass c;
    }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Class definitions are normally put in header files, which are included in the *.cpp file. This is done do that the class can be used anywhere within the program, not just main(). Right now you are probably writing very simple programs that contain only a main() function. What would you do with a program that has hundreds or even thousands of functions? You can't (or don't want to) define the same class over, and over for hundreds of times at the beginning of each function that needs it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Hard to tell without seeing the structure. Also you should be checking the return value of SystemList::GetNode() for NULL so that the program doesn't try to write out a NULL pointer.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Is sizeof(SystemNode) == 8192??? Please post that structure/class.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Correction: vector<string> Players::info;

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Depends on what the external symbol was. Did you see the second part of my answer, or does that error refer to something else (the error message should have told you the name of the symbol)?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

make the vector static.

class Players{
public: static vector <strings> info
};

Then in one of the *.cpp files declare it again as if it were a global variable

// Players.cpp
#include "Players.h"

Players::vector<string> info;
thines01 commented: Direct / wise +11
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Drop both those compilers because they are too old. Get free Code::Blocks (with MinGW compiler) or VC++ 2010 Express. You can easily compile libraries with either of those compilers/IDEs.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Just use Notepad or Notepad++, both are free and easy to use.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You need to learn how to recognize and correct errors.

double** changeArray(int rows, int columns)
{
	double **array = new double*[rows*sizeof(double*)]; 
	for(int i = 0; i < rows; i++)
	   array[i] = new double[columns]; // allocate columns for each row
	return array;	
}
int main(int argc, char *argv[]) {
	
	int rows = 10;
	int columns = 30;
	
	double** array = changeArray(rows, columns);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 7 was slightly incorrect. It should have been this:
double **array = new double**[rows*sizeof(double*)];

Also in the code you posted, changeArray() is not called from main()

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

A 2d array might look something like this: Note that it has 2 asterisks, not just one.

double **array = new double[rows*sizeof(double*)]; // allocate the rows number of pointers
for(int i = 0; i < rows; i++)
   array[i] = new double[cols]; // allocate columns for each row
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

matrix is a 1d matrix, not a 2d matrix. You can keep it as a 1d matrix if you want to but that means you have to calculate the row and column index yourself.

This is one of the rare times I could start the i counter with 1 instead of 0 so that the calculation (i-1) does not become a negative number. And this needs two loops, not one.

for (int i=1; i<= rows; i++)
{
    for(int j = 0; j < colums; j++)
        cout << matrix[((i-1) * rows) + j];   
}
phorce commented: Great help :) - Thanks +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I assume you mean 64-bit processors. The answer is yes because they are still in the x86 family of processors. Intel didn't completly replace the 32 and 16-bit processors, they added to them. 64 and 32 bit processors still use the 16 and 8 bit processor instruction set.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

rohan: you have the right idea, but the code is incorrect. You have to allocate memory for my_strings

#include <iostream>
#include <cstring>

char ** tokenize_urls()
{
	char **my_strings;
	char *temp[3] = {"first","second","third"};

	my_strings = new char*[3]; // allocate memory for the array
	for(int i = 0; i < 3; i++)
	{
		my_strings[i] = new char[20]; // allocate memory for each string
		strcpy_s(my_strings[i],20, temp[i]); // duplicate the string
	}
 
	return my_strings;
}
 
 
void process_and_display_information()
{
	char  **my_new_char = tokenize_urls();
	for(int i = 0; i < 3; i++)
        {
		std::cout << my_new_char[i] << std::endl;
                delete[] my_new_char[i]; // delete the memory this string
        }
        delete[] my_new_char; // delete the array
}

int main()
{
	process_and_display_information();
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

See this tutorial for C# arrays

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You are not allowed to change the datatype of an object -- in this case you can't reassign the data type from triangle* to rectangle*. Just use a different variable name for each one.

>>I deleted pointer, aka deallocated the memory.
delete operator only deletes the memory assigned to the pointer, not the pointer itself.

>>I thought that was the whole point of using 'pointers'.
You have a misconception of what pointers do. Its just like any other object, you can't have two or more objects with the same name.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

parsers start at the top of the program (line 1) and work themselves down. The bottom up approach would be a little like you trying to read a book backwards.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There will be no arks since its the end of the world. The end will come due to our sun exploding or collision with an asteroid, not because of a flood.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Is there any quick way i can do a goto line without seeking through the whole file or is that asking too much?

Depends. If it is a file that you want processed only once, then the answer would be no. But if you need to process the file multiple times either in the same or different sessions then maybe. What I have done in such cases is to create an index file that contains a key field and offset to that line in the original file. This index file is much smaller than the original cvs file, can be sorted after it is created so that your program can use binary search techniques on it (assuming the key file is a binary file). If you don't want to do that then the only alternative I have is to read the whole file serially until you get to the desired line.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Have you read this tutorial?