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

learn win32 for a PC first because its a lot easier to debug. There are lots of tutorials, such as this one.

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

its almost identical to XP. There are some differences but you will learn them as you go an read the MSDN articles about the functions. If you know win32 on XP then doing the same on a smart device is not difficult.

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

I only have the Express edition which doesn't have that option. But I did worked with pro edition of 2005 compiler and that is the option needed to start a project for the wireless devices I was talking to. In addition to the compiler you have to get Device Driver SDK from the manufacturer of the hardware, such as from Symbols Technologies, Intermect Inc., etc. The 2005 compiler came with a smart device emulator while will let you get started coding for the os in general terms, but the emulator has very limited capabilities. There are lots of things the emulator can't do because they require physical hardware.

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

you mean a wireless device such as a cell phone or barcode scanner? I would imagine it would depend on the compiler and the device type. I've done programming with Mobile 5.0 and Pocket PC operating systems on a barcode scanner (Symbols and Intermec) Those two scanners have completely different programming API even though they are running the same os.

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

line 6 is unnecessary.

you are not null-terminating the destination string. wcslen() returns the number of characters in the string and does not include the null terminator. So add a line after line 10 to null terminate the destination string.

You could also have just used wcscpy() and not bother with all the hassle of rolling your own copy function.

DarthPJB commented: great understand of the problem and solution +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Not to worry. Been there and done that. It often helps to have another pair of eyes look at a program.

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

your program crashes because line 3 is a pointer that is not allocated. Remove the stars on lines 3, 15 aned 17.

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

>>it sorts but then just quits out of the program for no reason..
Nope. It quits because there are problems with the code you wrote. Please post the code so that we can help you.

The basic idea of sorting structures is the same as sorting an array of integers. The only difference is swapping structures instead of integers.

struct person temp = p[i];
p[i] = p[j];
p[j] = temp;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> // when i compile it says error is here
I suspect you failed to include <string> header and/or failed to identify the namespace. But again I don't know because I can't see your monitor.

#include <string>
...
...
std::cout << fight[n].name << std::endl;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>only prob i have now is storing it in2 an class array

What array? You need to post the exact class declaration instead of making us guess what you are doing.

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

and it (I mean, including <string.h> ) does not produce any backward warnings at all...

why should the compiler produce warnings? string.h defines functions such as strcmp(), strcat(), etc. which are related to character arrays, not std::string. Those functions and that header file were inherited from C language.

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

Are you sure that this program compiles? You seem to have used string in your code, but you haven't included <string.h> at all...!

That's because std::string is not declared in <string.h> -- its in <string> header file. And some compiler include <string> with <fstream>

tux4life commented: Correct! +6
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't have that compiler, but browse through the project options and see if there is a flag to build 64-bit programs.

also browse these google links

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

compiling on a 64-bit operating system is not sufficient -- you have to build it with a 64-bit compiler.

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

>>if (answer1 == 'Leave')

answer1 is just a single character and you are attempting to compare it, illegally by the way, to a string. You need to make answer1 a character array and use strcmp() to compare it to a string. Or you could make answer1 a std::string object, since this is c++. Note the double quotes around "Leave".

std::string answer1;

...
cout<<"You awake and get out of bed and realize that you want to go kill a dragon for no reason. Now what? ";
cin >> answer1;
if (answer1 == "Leave")
	right = 1;
else
	right = 0;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Where? ;)

Oops! link added.

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

Here is one way to do it , I think, without the complications of COM. The GUI interface is probably not what you want but you can extract the ideas that document presents.

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

I would stick with the conventional method. Why? Because it makes the program easier to read and understand. And the next guy who has to maintain your program will hate you for that code. Use the KISS principal (Keep It Simple Stupid)

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

>>What do you think of this technique, is it useful
I never used or seen that technique -- I would have just done this:

mc.Foo();
mc.Bar();
mc.Pancakes("flour etc.");

>>Didn't know you could use this like *this
That is a very useful technique to remember because its use a lot, especially when you want to override the << and >> operators.

>>By the by, is this how they structured PHP?
No idea.

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

you are close

#include <iostream>
#include <string>
#include <cstring>
using namespace std;

class MyClass{
public:
	MyClass Foo();
	MyClass Bar();
	MyClass Pancakes(string ingredients);
};

MyClass MyClass::Foo(){
	cout<<"Inside foo\n";
	return *this;
}

MyClass MyClass::Bar(){
	cout<<"Inside bar\n";
	return *this;
}

MyClass MyClass::Pancakes(string ingredients){
	cout<<"To make pancakes you need: " << ingredients << "\n";
	return *this;
}

int main(){
	MyClass mc;
	mc.Foo().Bar().Pancakes("flour etc.");
	return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Ah, that explains alot! How about making a global variable static?... will that make the global only known within the... eh.. file?

That's correct. The static keyword works a little differently when used within a c++ class. Here are some google links for more information.

Also, how do you destroy a static vector? or a vector in general for that matter?
(Thinking of adding a DestroyHandle() function)

Since main() has a pointer to it then just use the vector's erase() method to destroy it. menu->erase(); Do not attempt to delete that pointer!

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

Ah, hahaha, just adding the 'static' made everything work.
So, a static variable is like declaring it in the global scope?

Yes, but when declared inside a function it only has scope within that function.

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

just like your original post, but make the vector static static vector<string> v;

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

why are you trying to dynamically allocate that array? Just hard-code it bool visited[11][55]; then delete lines 4 and 11.

If it must be dynamically allocated, then you will have to do it like this:

visited = new bool*[11];
      for(int i = 0; i < 11; i++)
          visited[i] = new bool[55];
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The code you posted is slightly different than the code in the origina post in that this new version returns a complete vector, not just a pointer. When CreateHandle() returns the compiler will duplicate the entire vector before leaving the function, then duplicate it all over again on line 16 for vector menu. For large vectors that can be very very time consuming which would not be acceptable in any professional program.

There are two alternatives:
1) make the vector static so that its contents are never ever destroyed until the program itself exists, then return a pointer to it.

2) pass it by reference as I previously mentioned.

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

>>Anyone know why this doesn't work?
Because the vector is destroyed when function testor() returns to its caller. A better way is to pass the vector by reference to testor()

void testor(vector<string>& v)
{
	v.push_back("Lolzer");
}

int main()
{
    vector<string> v;
    testor(v);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It doesn't compile with VC++ 2008 Express either. The compiler didn't like the preprocessor directive on line 1002, chkconf.h. So I changed it to this:

#ifdef wxUSE_CRASHREPORT
#if !wxUSE_ON_FATAL_EXCEPTION
#   ifdef wxABORT_ON_CONFIG_ERROR
#       error "wxUSE_CRASHREPORT requires wxUSE_ON_FATAL_EXCEPTION"
#   else
#       undef wxUSE_CRASHREPORT
#       define wxUSE_CRASHREPORT 0
#   endif
#endif /* wxUSE_CRASHREPORT */
#endif

After that, the compiler issued the error message on line 1819. error "wxClipboard requires wxDataObject"

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

Everyone gets bad rep from time-to-time, don't worry about it. Feel lucky I didn't give that bad rep because it would have cost you 23 points instead of the 4 points Killer_Typo gave you.

~s.o.s~ commented: Is this a threat or wut? :-) +28
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>But I need to know what are the best practices for code sharing, like:

For every 1,000 programmers there are 1,000 coding styles! Every coder develops his/her own coding style or use the coding style standard set by the company. A good place to start is the links that siddhant posted and by reading current programming books, paying attention to the coding styles presented on those books. Eventually you will develop your own style in a way that makes sense to you.

There is no such thing as a "deprecated coding standard or style" because there were never any official C or C++ coding standards to begin with.

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

Abstract classes (I presume you mean it contains one or more pure virtual functions) can not be instantiated by themselves. So there is no way to make an array of them. You could, however make a vector of them vector<Holding*> array;

#include <vector>
using namespace std;

class A
{
public:
    A() {x = 0;}
    virtual void foo() = 0;
private:
    int x;
};

int main()
{
    vector<A*> array;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

use the new operator to allocate dynamic memory Holding *holdLib = new Holding[size];

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

lines 36 and 37: delete these lines because they are just a temp pointers and can not be deleted.

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

I have a good friend I've known for 20 years who is from India and I still can't pronounce is name correctly! It doesn't seem to bother him because he never said anything about it, he probably just understands that it is a difficult name for Americans to pronounce.

My advice is not to let it bother you too much that we mispronounce your name.

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

zero -- I don't listen to music on the internet.

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

I think a name change would be a great idea :) John Doe or Bill Smith would be a good names to inherit.

>>and i wont feel like foreigner each time i am asked what my name is
But you are a foreigner. Technically we are all foreigners except the native American Indians.

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

Does the service program have permissions to do that? You might have to have the service log in with an administrator account.

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

Highest() returns the wrong value -- it should return the index value (value of i loop counter) of the student with the highest grade. You will need to add another variable to keep track of that too.

There are a couple ways to implement those functions:

1) in main(), first call highest() and then pass its return value as another argument to print()

2) in print() add another ifstream argument, just before the last line of print() call highest() then print its return value.

outFile << "Student with the Highest score: " 
        << Highest(ifile, students) << endl;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you could do this:

void CMFC1Dlg::OnBnClickedButton1()
{
        char *ptr;
	if( m_POpened )
	{
		CString cmd;
		m_EditCmd.GetWindowTextA( cmd );
		m_Port.WriteToPort( (ptr = va( "%s%c", cmd, 13 )));
                delete[] ptr;
	}
}

or this:

const char* va( char* FormatStr, ... )
{
	va_list ArgPtr;
	static char FinalString[2048];
	va_start( ArgPtr, FormatStr );
	vsprintf_s( FinalString, sizeof(FinalString), FormatStr, ArgPtr );
	va_end( ArgPtr );
	return FinalString;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

memory is allocated on line 10 but never deleted. Try this:

void CMFC1Dlg::OnBnClickedButton1()
{
        char *ptr;
	if( m_POpened )
	{
		CString cmd;
		m_EditCmd.GetWindowTextA( cmd );
                ptr = va( "%s%c", cmd, 13 );
		m_Port.WriteToPort( ptr);
                delete[] ptr;
	}
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>What types of job positions are computer programmers needed for, Other than the obvious software development types?

I've had programming jobs at banks, accounting, manufacturing plants, government, and military. The most interesting ones to me were at the manufacturing plants, such as donuts, paper mills, tooth brushes, and jellybeans, just to mention a few. All those factories needed programmers to customize the computer software on assembly lines.

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

If the program knows the HWND handle then call SetWindowLong() to hook into its default proc

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

Yes, function pointers might be helpful, but you would still have to have a list of pre-defined functions just as I had in the code I posted. For example if the command string were "say hello" the program could not call a function say() at run time unless it was already known at compile time.

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

where did you declare array item?

Change the while statement to while( i < sizeof(item)/sizeof(item[0]) && fscanf(...) > 0) . Note: if item array is a paremeter to the function you posted then that sizeof() stuff will not work.

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

something like this:

void foo( int x = 0)
{
   switch( x )
   {
       case 0:
           printf("case 0\n");
           break;
         case 1:
           printf("case 1\n");
           break;
        default:
           printf("default\n");
           break;
    }
}

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

try this version

int cat(char **lawl, const char *catftw, const char *sub); 

int main()
{
    char adir[] = {"C:\\somedirectory\\"};
    char subdir[] = {"content\\"};
    char *dir; 
    int len;// pretty sure these char values are not initialized correctly
    cout << adir << endl << subdir << endl;
    len = cat(&dir,adir,subdir); // when properly initialized and passed no error in build but stops fails after getting lenths
    cout << len << "\n" << dir << "\n";
    return 0;
}


int cat(char **lawl, const char *catftw, const char *sub)
{
    int lens,lenm,tlen,x;
    char* ptr;
    for(x=0;catftw[x]!=0;x++)
        ;
    lenm = x;
    cout << lenm << endl;
    for(x=0;sub[x]!=0;x++)
        ;
    lens = x;
    cout << lens << endl;
    tlen = lenm + lens + 1;
    cout << tlen << endl;
    *lawl = new char[tlen];
    ptr = *lawl;
    while(*catftw)
	{
	    *ptr++ = *catftw++;
	}
    cout << *lawl << endl;
    while(*sub)
	{
	    *ptr++ = *sub++;
	}
    *ptr = '\0'; // null terminate the string
    cout << *lawl << endl;


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

the function does not need double star pointers (pointers to pointers). Therefore this line will not work right for(x=0;catftw[x]!=0;x++); >>lawl[x] = catftw[x]; //gives error when catftw properly initialized

As Gomer Pyle would have said: "Surprise, surprise surprise". lawl is a double star pointer and that line is treating it as a single star pointer.

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

>>Is there a way to define the < operator for Object somehow such that I can do this without having to modify Tools?

Of course there is. That's how std::sort function does it -- one of the arguments to std::sort is a user-defined function pointer, which sort() calls to determine sort order.

How to do it would depend on that Tools sort function and its arguments.

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

you would have to post all that code -- it shouldn't matter what *.cpp file contains main().

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

>>Also please note that the variables mentioned in the errors are not used at all in a2main.cpp they were defined in console.c then redefined in screen.cpp,

You can't declare the same variables in two or more *.cpp files. Declare them in only one *.cpp file and use the extern keyword to declare them on other files. See example in my previous post.

Some compilers will discard unused variables during the optimization process, but apparently yours does not. In the case of your program I doubt any compiler would discard them because it doesn't know until link time whether the variables are actually used or not.

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

The most common reason for those duplicate declaration errors is declaring variables in header files without the extern keyword. extern tells the compiler that the object is actually declared in some other *.cpp or *.c file.

Here is an example of how you must declare variables in header files

// consol.h
#ifdef _cplusplus
extern "C" {
#endif
extern int _line;
extern int _cursor_pos;
extern int _col;
#ifdef _cplusplus
};
#endif

Now, in one and only one *.cpp file you have to declare them without the extern keyword

//console.c 
#ifdef _cplusplus
extern "C" {
#endif
int _line = 0;
int _cursor_pos = 0;
int _col = 0;
#ifdef _cplusplus
};
#endif