Concatenate ".textNumber"

Non-platform specific questions.

Concatenate ".textNumber"

Postby jamtc » Sat Jul 01, 2006 11:47 pm

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:
JamTC
:-)
User avatar
jamtc
 
Posts: 12
Joined: Fri Jun 16, 2006 12:37 am
Location: Sao Paulo - Brazil
Score: 0 Give a positive score

Postby DilloDude » Sun Jul 02, 2006 12:59 am

Youcould use:
Code: Select all
char add[3];
sprintf(actor.text, "%d", Actor1.textNumber);
sprintf(add, "%d", Actor2.textNumber);
strcat(actor.text, add;
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby jamtc » Sun Jul 02, 2006 2:14 am

I need to compare this number (1734) so I need a ".textNumber"

How can I do that ?

:oops:
JamTC
:-)
User avatar
jamtc
 
Posts: 12
Joined: Fri Jun 16, 2006 12:37 am
Location: Sao Paulo - Brazil
Score: 0 Give a positive score

Postby DilloDude » Sun Jul 02, 2006 4:13 am

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby Just4Fun » Sun Jul 02, 2006 3:46 pm

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.
I've learned that I still have a lot to learn.

** Makslane == Genious **
Just4Fun
 
Posts: 524
Joined: Tue Jul 01, 2003 5:19 am
Location: USA: Washington State; West Coast
Score: 6 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest