I have a basic question with a for loop statement where I have a function thats creating input nodes inside my animation program.
The name thats assigned to the input that the function creates is "InputNum" . How do I tack on the value of i to the end of the "InputNum" character string?

int i;
for (i=0;i<36;i++)
{
mInputs[i] = AnimationNodeInCreate ( i, "InputNum", ANIMATIONNODE_TYPE_NUMBER );
}

Recommended Answers

All 4 Replies

Use sprintf (or snprintf (if available this is the best )) to create a string in the form of "InputNumber%d", and pass that to the AnimationNodeInCreate function.

int i;
char label[ 15] = "";
for (i=0;i<36;i++)
{
         sprintf ( label, "InputNum %d", i );
         mInputs[i] = AnimationNodeInCreate ( i, label , ANIMATIONNODE_TYPE_NUMBER );
}

Thanks alot wolf.
I have one more question with my loop if you dont mind.
The ANIMATIONNODE_TYPE_NUMBER is one type of argument that the function accepts and it defines the input to be a float input, but I can also define my input to be a Vector type if I used ANIMATIONNODE_TYPE_VECTOR instead.

Now the problem is I have a total of 93 inputs that I need to create (36 float type and 57 Vector type)
The problem is the inputs are not in a clean sequence, meaning the first 3 inputs are vector type, then the next 2 are number type, then again 3 vector, 2 num.... etc and it alternates like that..
So How would I setup a loop to handle the 3 vector, 2 num type of a sequence?

Use sprintf (or snprintf (if available this is the best )) to create a string in the form of "InputNumber%d", and pass that to the AnimationNodeInCreate function.

int i;
char label[ 15] = "";
for (i=0;i<36;i++)
{
         sprintf ( label, "InputNum %d", i );
         mInputs[i] = AnimationNodeInCreate ( i, label , ANIMATIONNODE_TYPE_NUMBER );
}

The format I would use is

sprintf ( label, "InputNum%04d", i );

This will tack on the number without spaces, and the number will be 4 digits, zero filled -- InputNum0023 -- but that's just me... :mrgreen:

I have one more question with my loop if you dont mind.
The ANIMATIONNODE_TYPE_NUMBER is one type of argument that the function accepts and it defines the input to be a float input, but I can also define my input to be a Vector type if I used ANIMATIONNODE_TYPE_VECTOR instead.

Now the problem is I have a total of 93 inputs that I need to create (36 float type and 57 Vector type)
The problem is the inputs are not in a clean sequence, meaning the first 3 inputs are vector type, then the next 2 are number type, then again 3 vector, 2 num.... etc and it alternates like that..
So How would I setup a loop to handle the 3 vector, 2 num type of a sequence?

Don't know if I understand your problem correctly, but there are a number of ways that you can solve this problem by using various kinds of loops.
One would be to use a loop that counts to 93, and check it the remainder or dividing the loop counter with 5 to decide if it is a vector or float.

for ( i = 0 ; i < 93; i++)
{
         switch ( i % 5 )
         {
                     case 0:
                     case 1:
                     case 2:
                               // this means the vector type
                               sprintf ( label, "InputNum %d", i );
                               mInputs[i] = AnimationNodeInCreate ( i, label , ANIMATIONNODE_TYPE_VECTOR );
                                break;

                     case 3:
                     case 4:
                               // this means the float type
                               sprintf ( label, "InputNum %d", i );
                               mInputs[i] = AnimationNodeInCreate ( i, label ,    ANIMATIONNODE_TYPE_NUMBER)
                               break;
         }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.