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

Prabakar 77 Posting Whiz

I don't understand why getline() did not work.
Here is a code that uses getline as lener suggested.

#include <iostream>

#define isupper(a) ((a)>= 'A' && (a)<= 'Z') 
#define islower(a) ((a)>= 'a' && (a)<= 'z') 

using namespace std ;

int main()
{
    char PlainText[100], CipherText[100] ;
    cin.getline(PlainText, 100) ; 
    for ( int i = 0 ; PlainText[i] ; i++ )
    {
        if ( isupper(PlainText[i]) )
            CipherText[i] = 25 - (PlainText[i] - 'A') + 'A' ;
        else if ( islower(PlainText[i]) )
            CipherText[i] = 25 - (PlainText[i] - 'a') + 'a' ;
        else CipherText[i] = PlainText[i] ;
    
    }
    cout << CipherText ;
    cin.get();
    return 0 ;
}

EDIT:

string class could be used rather than array of char.

Prabakar 77 Posting Whiz

1)cin reads a array of char until a delimitter like <space> or <new line> is encountered. Thats why the program might have stoped after chaging the first letter.

2)The converstion you've made could be done by math exprestions rather than that many if struct.

Hope this helps:)

Prabakar 77 Posting Whiz
for ( exp = 0, resultado = 1 ; exp < exponente ; exp++ )
    resultado *= base ;
cout << " The result is: " << resultado;

Is this what you are looking for?

Prabakar 77 Posting Whiz
void squares(int n)
{
    if( n== 1 ) 
        cout << 1 ;
    else
    {
         cout << n*n << " " ;//swap lines 7 & 8 for ascending order
         squares ( n- 1 );
    }
}
Prabakar 77 Posting Whiz

Array index starts with 0 & there is a total of 8 elements. So, the first no to be checked is (7-0)/2 = [3]. The second is 3+(7-3)/2 = [5].

Prabakar 77 Posting Whiz

You can make your program to sleep

This link may be useful

Prabakar 77 Posting Whiz

Oh my god! Guess I have to throw my book. I am learning everything wrong.

Prabakar 77 Posting Whiz

Works great in Dev C++ too!

Little tips. May be they are useful.

While compiling in turbo c++ change #include<iostream> to #include<iostream.h> same goes for "string" I believe you know this already

I remember you saying that you have never worked with Visual C++. While selecting the type of project did you select console or Win32?

Prabakar 77 Posting Whiz

didn't I give a link to learn ODBC database connectivity

Prabakar 77 Posting Whiz

Thanks, now I understand why calling (*main)() worked for me sometimes back

Prabakar 77 Posting Whiz

<< int (*p)( void ) = &foo;

'foo' by itself is the address of the fn.
so
int (*p)( void ) = foo;
will be enough, if I am right.

Prabakar 77 Posting Whiz

Well, I guess you must thank IVAILOSP, for writing the code for you. Since passwords are small, Its difficult to decipher this poly alphabetic substitution algorithm, unless the crypt analyzer has the key "lolz".

Hints:

1) You may use this algorithm to encrypt the password & store in file
2) retrieve & decrypt the string using this algorithm again.
( In this case encryption is same as decryption )
3) compare with what you got from user.

4) Use a different algorithm for added safety for the data to be stored.

Prabakar 77 Posting Whiz

Oh God!. Think of a way on the first hand

You have the passwords encrypted in the file Don't you.

Prabakar 77 Posting Whiz

I run your program in college & all I had was a ball which run from one end to another end with blue background & green basement:). No flashing occurred:-O Perhaps your program may not be your problem.;)

And I realize that getch() causes no problem.

Just for my curiosity, what are you doing?:?:

And then, I would suggest a class for the ball & the background, but without knowing what you are doing I am not sure if it is a good suggestion.

Prabakar 77 Posting Whiz

http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/rzaik/rzaikodbcapicplusplus.htm

I got this from google. Hope this is what you want.

If you are already half way in your project its up to you to start from scratch.

As I said before poly alphabetical substitution & transpositions can be effective as well.

Prabakar 77 Posting Whiz

Just saw one of your question. You want to know how to access databases. Then turbo c just cant help you. I have accessed database with C++ not long before but I need some time to reply properly.

Prabakar 77 Posting Whiz

for data encryption,

If you use visual c++ You can have your data in MSAcess database & all those password security becomes easier. I suggested MS Access because thats what I know. But Oracle, I heard, has many more features.

Else you want to encrypt the file with your program then There are many cryptographic techniques

The most easiest and weakest algorithm, I suppose, is Caesar cipher.

Then Instead of using complex algorithms like MD5 or all those SHAs which makes my head swing while programing. I would choose a combination of transposition & substitution algorithm. Its comparatively easier.

Google these for more details

Hope this helps:)

EDIT: The more complex the algorithm, the more security you can provide.

Prabakar 77 Posting Whiz

I am pretty confident that experts in this forum wont like talks about turbo c++. well, I shall give you a clue.

getch() does not echo the char typed yet reads it.
putch() can be used to put a char of your liking.

Need you know anything more than this to solve the problem?

Coming to compilers. My academics has limited me to turbo c++ for some time untill I joined this fourm, where as you can start with the right compilers. Code::Blocks, Dev C++ & Visual C++ (express edition) are 32 - bit free compilers and provides you both win32 & console application. You can start with them on the first hand.
My suggestion, Uninstall Turbo C++, Like i did

Prabakar 77 Posting Whiz

Do you want to encrypt your file. Or just the * when the password is typed?

If you want to hide the password when user types check my post else

Google for MD5 or SHA or any such algorithm to encrypt the file so that the contents will be confidential.

Prabakar 77 Posting Whiz

1) Don't use void main
2) Don't use Turbo C++
3) If it is a must to use Turbo C++, try getpass() or write one on your one to simulate it. Its ain't difficult.