Page 2 of 2

Re: Memory increasing question

PostPosted: Fri Oct 14, 2011 3:44 am
by EvanBlack
did u try

Code: Select all
char getFullName (const char *cname, int cindex)
{
   char buffer[50];   //Create char array
   sprintf(buffer,"%s.%i",cname,cindex); // attach clone index number to actor name.
   return(buffer);
}

Re: Memory increasing question

PostPosted: Fri Oct 14, 2011 3:01 pm
by Leif
Yes, it displays error

"Error line 5: Incompartible types:cannot convert from ' * char ' to 'char'

Re: Memory increasing question

PostPosted: Fri Oct 14, 2011 3:19 pm
by Leif
Well, suddenly i found solution )) This does not eat memory ))
Thanks, guys for helping ))

Code: Select all
char ActorName[50];

char * getFullName (const char *cname, int cindex)

{
    char *buffer = ActorName;
    sprintf(buffer,"%s.%i",cname,cindex);
    return(buffer);
}

Re: Memory increasing question

PostPosted: Fri Oct 14, 2011 9:14 pm
by skydereign
I'd avoid doing that, as that isn't what functions are for. Anyways, the error is telling you exactly what the problem is. Your function's return type is char, even though you are trying to return a string. You fixed that in your new function, but you don't have to create the variable outside the function.
Code: Select all
char*
getFullName (const char *cname, int cindex)
{
   char buffer[50];   //Create char array
   sprintf(buffer,"%s.%i",cname,cindex); // attach clone index number to actor name.
   return(buffer);
}

Re: Memory increasing question

PostPosted: Sat Oct 15, 2011 6:44 am
by Leif
I understand, that it's not "optimal" solution.

But another propositions does not work anyway...
In future i'll use getclone2 function

Re: Memory increasing question

PostPosted: Sat Oct 15, 2011 7:21 am
by skydereign
That function that I posted does exactly what your fix does, except that it contains the string in the function. The only reason that it was originally giving you any problems was that you were trying to return a char, instead of a char*.