Page 1 of 1

Concatenate ".textNumber"

PostPosted: Sat Jul 01, 2006 11:47 pm
by jamtc
Hi Again !

I want to concatenate two .textNumber in a just one.

Example:

actor1.textNumber = 17
actor2.textNumber = 34

I want to create a new "actor.textNumber" with a number 1734.

How can I do that ?

:roll:

PostPosted: Sun Jul 02, 2006 12:59 am
by DilloDude
Youcould use:
Code: Select all
char add[3];
sprintf(actor.text, "%d", Actor1.textNumber);
sprintf(add, "%d", Actor2.textNumber);
strcat(actor.text, add;

PostPosted: Sun Jul 02, 2006 2:14 am
by jamtc
I need to compare this number (1734) so I need a ".textNumber"

How can I do that ?

:oops:

PostPosted: Sun Jul 02, 2006 4:13 am
by DilloDude
If you know that the number of digits in the second variable will always be 2, you can try
Code: Select all
actor3.textNumber = (actor1.textNumber * 100) + actors.textNumber;

This will get actor1's text number (17) times 100 (1700) and add it to actor2's textNumber (34), which will result in 1734. If you want to be able to have only one digit in actor2, say 6, then this would produce 1706, as opposed to 176. If you wanted 176, you would need to know the number of digits in actor2.

PostPosted: Sun Jul 02, 2006 3:46 pm
by Just4Fun
You can also manipulate the text to get the new actor "1734":

Code: Select all
    strcpy(n3.text,n1.text);  //copy first number '17' into new actor
    strcat(n3.text,n2.text); //concantenate number '34' onto '17'
    strcpy(cDisplayValue,n3.text); //var to hold the char
    iDisplayValue = atoi(cDisplayValue); //convert the char to a number


As far as doing a comparison of values:
Code: Select all
  if(iDisplayValue >= iMyOtherValue){
     do something
   }
//use the strcpy,strcat, and atoi functions to manipulate your text and numbers...


HTHs.