Memory increasing question

Non-platform specific questions.

Re: Memory increasing question

Postby EvanBlack » Fri Oct 14, 2011 3:44 am

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);
}
(\__/) ( Soon... The world)
(O.o )< will be mine!____)
(> < )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bunny Overlord 2012!
EvanBlack
 
Posts: 202
Joined: Fri Sep 30, 2011 10:17 am
Score: 19 Give a positive score

Re: Memory increasing question

Postby Leif » Fri Oct 14, 2011 3:01 pm

Yes, it displays error

"Error line 5: Incompartible types:cannot convert from ' * char ' to 'char'
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score

Re: Memory increasing question

Postby Leif » Fri Oct 14, 2011 3:19 pm

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);
}
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score

Re: Memory increasing question

Postby skydereign » Fri Oct 14, 2011 9:14 pm

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);
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Memory increasing question

Postby Leif » Sat Oct 15, 2011 6:44 am

I understand, that it's not "optimal" solution.

But another propositions does not work anyway...
In future i'll use getclone2 function
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score

Re: Memory increasing question

Postby skydereign » Sat Oct 15, 2011 7:21 am

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*.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Previous

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest