convert address to string value?
Hi
Please help. Moving from vb to C++ and can't figure how to get the string value of the address for something like this:
Code:
#include <stdio.h>
int main ()
{
// Make 52 cards in deck
//define suit and card value for each
int suit;char* cardNom;
for (int i=1;i<=52;i++)
{
suit = i / 13;
switch (suit)
{ case 0: cardNom = "Spades";
break;
case 1: cardNom = "Hearts";
break;
case 2: cardNom = "Clubs";
break;
case 3: cardNom = "Diamonds";
break;
}
switch (i)
{ case 0: cardNom = "Ace of " + char(cardNom);
break;
case 10: cardNom = "Jack of " + char(cardNom);
break;
case 11: cardNom = "Queen of " + char(cardNom);
break;
case 12: cardNom = "King of " + char(cardNom);
break;
default: cardNom = char(i + 1) + " " + char(cardNom);
break;
}
printf ("\nCard number: %d" , i);
printf (" is the %d" ,char(cardNom));
}
return 0;
}
Re: convert address to string value?
Learn about proper string handling in C, or perhaps in C++. (C++ is easier, but C is closer to what you're already trying to do.) malloc, free, strcpy, strcat and strlen in C. std::string in C++.
Re: convert address to string value?
You're handleing the cases like c++ strings although you're a little off. Make cardNom a string and use it like so:
case 0: cardNom += "Ace of " + cardNom; break;