Prabakar 77 Posting Whiz

First I don't understand the need to clone trees, having same data in two different places often cause problems than solving problems. Do you have a reason to do so?

sink = NULL;

Do you really expect this to free the memory you allocated? If so, you may have to go and read your c book again

May be you'll have to check before you recurs again

sink->val = source->val;
if(source->left){
    sink->left = malloc(sizeof(tree));
    copy_tree (sink->left, source->left);
}else{
    sink->left = NULL;
}
if(source->right){
    sink->right = malloc(sizeof(tree));
    copy_tree (sink->right, source->right);
}else{
    sink->right = NULL;
}

Please don't PM for answers

Prabakar 77 Posting Whiz

killdude69, the only way you could hold on to your argument is to talk on situations in which portability has no value. Say, while developing vertical solutions to a non IT based company which uses windows environment, there is no point in providing portability as a feature cause it means nothing to your customer(the customer uses only windows and wouldn't like the distribution of the software to other companies, as in the licence agreement)

In such cases, it is better to exploit tools provided by Microsoft, even if its exactly what Microsoft wants.

In the end its your choice. Be a slave to microsoft or not.

But, I much prefer programs that run on Linux than on windows cause I am a linux lover. Linux is a life saver to people like me who cannot afford to buy windows and who do not want to pirate:$

And you can't deny the fact that you were wrong when you said that you know the source code of win32 api.

To be ignorant is not a big problem, but not to be able admit mistake and learn from it is a problem.

Cheers:)

Prabakar 77 Posting Whiz

I do not have vista, to help you:( I don't know why it is not working in vista, these functions are ment to work on windows after all. Perhaps you'll have to wait for others to respond

Prabakar 77 Posting Whiz

Okay let me be brief,

1) Don't use conio.h
2) Don't use void main. int main is the standard way
3) so many if else statements? what if you need the diamond to be bigger. The following code is as good as yours

puts("    *");
  puts("   ***");
  puts("  *****");
  puts(" *******");
  puts("*********");
  puts(" *******");
  puts(" *******");
  puts("  *****");
  puts("   ***");
  puts("    *");

Here is a different way of doing it, in c

#include<stdio.h>
#include<math.h>
int main ()
{

  int i, j, n=5; // n controls the size of the diamond. 

  /*Remember that there is a restriction in the number of char the console window can put in a line, more than that the text will be wrapped messing up the diamond*/

  for (i=n; i>-n-1; i--){
    printf ("\n%*c", abs(i)+1, ' '); //Space to be provided
    for (j=2*(n-abs(i))+1;j;j--)
      putchar('*');
  }
  getchar();
  return 0;
}
Prabakar 77 Posting Whiz

Sorry to have suggested an untested code.
My little Google search found me this

Have a look at it.

This time I have tested the code and it really works.

ShellExecute(GetDesktopWindow(), "open", "\"D:\\program files\\Adobe Reader 9.exe\"", "/A page=45 Ubuntu.Pdf", NULL, SW_SHOWNORMAL);

D:\Program files\Adobe Reader 9.exe is the path to the portable reader in my computer(I always try to get portable versions).

Ubuntu.pdf was in the same folder as my CPP program, hence I did not specify its path.

Details about parameter options could be found int the link above.

Good Luck

marcosjp commented: Very helpful, saved my day with a great solution +1
Prabakar 77 Posting Whiz

The official way is with Win32 COM
(never use keybd_event, not professonal at all...)

I'll take a note of that.

And the actual answer is not either. Its just to give an argument to the pdf we are opening;)

Prabakar 77 Posting Whiz

EDIT:

On second thoughts, you are right.

Just a little change

ShellExecute(GetDesktopWindow(), "open", "c:\\someFolder\\myFile.pdf #page=4",  NULL, NULL, SW_SHOWNORMAL);

Just add a space, cause page=4 is an argument.

----------------
I don't know if there are any real ways to do it. But how about triggering some keyboard inputs with keybd_event()
All you have to do is Ctrl+Shift+N to open the "go to page" dialog box. and then the input the number 4(say) and also "Enter" with the same function. Before all this you have to give time for the pdf to get opened and become active(You may have to use the function Sleep())

You can get the complete set of Virtual key codes in msdn

Hope it helps

Prabakar 77 Posting Whiz

I have to leave now. But at a glance I saw that you use a strange way to print your rectangle class. Have you heard of friend functions? declare the operator<< function as a friend of rectangle.

Prabakar 77 Posting Whiz

Yes, thats right

Prabakar 77 Posting Whiz

endl manipulator in istream? remove it.

Prabakar 77 Posting Whiz

If you want to run MSWORD in multiple computers from a single computer then all you have to do is to send a UDP broadcast message to the clients, and the clients will just run the MSWord with the System.diagnotic.start("winword") You can also use Shell command but you'll have to give absolute address. So, I would prefer the first method. Its simple and it works:)

Prabakar 77 Posting Whiz

do you mean... System.Diagnostics.Process.Start( "winword" ) ?

Prabakar 77 Posting Whiz

Yes, return value will be negative or positive or zero. Relearn the basics of strcmp()

Prabakar 77 Posting Whiz

You can use also stringstream to convert to int

int final;
stringstream strm;
char * value_a = "123456";

strm << value_a;
strm >> final;

I never knew about that. This looks great

Prabakar 77 Posting Whiz

You can use the Library functions like atoi(), sscanf()

Prabakar 77 Posting Whiz

Why do you want to convert a character pointer to an integer? Such conversion are normally not done.

But the answer is int final = (int)value_a;

Prabakar 77 Posting Whiz

I agree with you CoolGamer & refer to my post. I didn't get that warning in that line. It was the line before it, that's why I suggested a type cast.
x = x||y ; x||y will return ( false||true == 0||1 == 1 ) This int is being assigned to the type bool hence the warning.

Prabakar 77 Posting Whiz

What? Never heard of that. Don't tell me,
this don't work
x = bool (x||y) ;

Prabakar 77 Posting Whiz

Its kind of strange. In my turbo c++ compiler I got that warning for the line x = x||y ; Besides, you don't assign anything in the if statement.

Warning D:\TC\BIN\NAME.CPP 14: Assigning int to bool in function main()

Line 14: x = (x || y);
As I said before type casting would do.

Prabakar 77 Posting Whiz

sorry, a little mix up. I used Turbo C compiler instead of turbo C++ which is strict when it comes to type checking. You just have to convert the int returned by x||y to bool x = (bool) (x || y);

Prabakar 77 Posting Whiz

I don't get it. I too use Turbo C++. I copied the code & run it. It had no problem(No Warning No error). But in Code::Blocks, Since bool was already known I had the error message. And then || operator returns integer as far as I know. returns 1 if true & 0 if not

Prabakar 77 Posting Whiz

Perhaps this:

#include<iostream>

int main ()
{
    unsigned long long u40=16825420246llu;
    unsigned long long u20=3171426llu;
    unsigned long long prod=u20*u20;
    double kx;
	
    kx=double(u40)/prod; 
    std::cout<< "u40: "<<u40<<" u20: "<< u20
        <<" Prod: "<<prod<<" kx: "<<kx;
    std::cin.get() ;
    return 0 ;

}
Prabakar 77 Posting Whiz

1) the overloaded operator << return a reference to the fin object
2) type casting to primitive data type is as follows.

class complex
{
       int r, i ;
public :
       operator int()
       {
           return r*r-i*i ; // some conversion to int
       }
       complex():r(0), i(0) { }
       complex ( int a, int b ) { r = a; i = b ; }
      
};

if both the source & destination are user defined then the function for the cast may be either in source ot in destination.
Conversion routine in source is similar to that of the primitive types. But in destination is a little different.

class dmy // source
{
    int day, mth, yr ;
 //methods
} ;
class date // destination
{
    char a[10] ;
// conversion routine
   public:
    date ( dmy t ){/*convert ints to char array*/}
};

Hope this helps:)

Prabakar 77 Posting Whiz

For some reason I was never notified that you have replied.

And yes, I used it to get '\n' in the first program. In the second program I forgot to delete it:P

Prabakar 77 Posting Whiz

Well the .bmp file explain it. I guess my the code should work fine.
flag is just a variable that I set to false(0) initially & if 7 or the point is reached flag is set to true(1) & hence exits out of the loop. you can set something like this too
int flag = 0 ;
and set it to 1 when conditions are met so that you can exit the loop
So is this code ok?

#include <iostream>
#include <time.h>      
int main()
{
    srand (time(NULL));
    using namespace std;
    int d1, d2;
    int suma = 0, punto = 0;
    char game;
    cout << " Wanna start ?? \n";
    cout << " 1 - YES, OF COURSE jeje\n";
    cout << " 2 - NO, GET ME OUT OF HERE\n Your Choice: ";
    cin >> game;
    while (game != '2')
    {
         cin.get() ;
         d1 = rand () % 6 + 1; 
         d2 = rand () % 6 + 1; 
         cout << "\n first dice is...  " << d1 << "\n\n";
         cout << " second dice is...  " << d2 << "\n\n";
         cout << " the sum up is... " << (suma = d1+d2) << "\n\n";

	switch (suma)
	{
	case 11: case 7:
            cout << " YOU WON \n\n";
	    break;
	case 2: case 3: case 12:
	    cout << " YOU LOST \n\n";
	    break;
	case 5: case 4:	case 6: case 8: case 9: case 10:
	    cout << " " << suma << " is your point \n\n"; …
Prabakar 77 Posting Whiz

Did you run my program?
I hope removing unnecessary output statements should help you get the desired output:)

Prabakar 77 Posting Whiz

I still don't understand part of the game. Is this what the game should do?

#include <iostream>
#include <time.h>      
int main(int argc, char* argv[])
{
    srand (time(NULL));
    using namespace std;
    int d1, d2;
    int suma = 0, punto = 0;
    char game;
    cout << " Wanna start ?? \n";
    cout << " 1 - YES, OF COURSE jeje\n";
    cout << " 2 - NO, GET ME OUT OF HERE\n Your Choice: ";
    cin >> game;
    while (game != '2')
    {
         cin.get() ;
         d1 = rand () % 6 + 1; 
         d2 = rand () % 6 + 1; 
         cout << "\n first dice is...  " << d1 << "\n\n";
         cout << " second dice is...  " << d2 << "\n\n";
         cout << " the sum up is... " << (suma = d1+d2) << "\n\n";

	switch (suma)
	{
	case 11: case 7:
            cout << " YOU WON \n\n";
	    break;
	case 2: case 3: case 12:
	    cout << " YOU LOST \n\n";
	    break;
	case 5: case 4:	case 6: case 8: case 9: case 10:
	    cout << " " << suma << " is your point \n\n";
	    punto = suma ;
	    bool flag = false ;
	    do
	    {
	        cout << " Press Enter to throw again... ";
                cin.get() ;
                d1 = rand () % 6 + 1;     // to dice start randomly
		d2 = rand () % 6 + 1;     // to dice start randomly
		cout << "\n first dice is...  " << d1 << "\n\n";
		cout << " second dice …
Prabakar 77 Posting Whiz

I believe do-while will serve you better than while(). You need not repeat 25 - 29 if you use do-while loop
Could you explain how the game works? so that I can think of a solution.

Prabakar 77 Posting Whiz

>> g = x ;
g has to be least of the 2 numbers rather than simply x for the code to be faster.
Why brute force?

Prabakar 77 Posting Whiz

I still believe your first suggestion of getline() is better