Function that Returns a String

Non-platform specific questions.

Function that Returns a String

Postby jazz_e_bob » Mon Aug 08, 2005 2:28 am

I need an example of a function that returns a string. :?

This is the kind of thing I want:

Code: Select all
char stateName( int stateID )
{
 
  char *result;
 
  switch ( stateID )
  {
    case 0: strcpy ( result, "STANDING" ); break;
    case 1: strcpy ( result, "WALKING" ); break;
    case 2: strcpy ( result, "RUNNING" ); break;
    case 3: strcpy ( result, "DYING" ); break;
  }

  return result;

}


Usage: strcpy ( debug.text, stateName(0) );
Controlling complexity is the essence of computer programming.
User avatar
jazz_e_bob
 
Posts: 742
Joined: Tue Jul 01, 2003 9:38 pm
Location: Bloke from Cockatoo Creek Australia
Score: 14 Give a positive score

Postby makslane » Mon Aug 08, 2005 8:30 pm

Use:

char *stateName( int stateID )
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby jazz_e_bob » Mon Aug 08, 2005 9:39 pm

Thanks mate.

GE Rocks!
Controlling complexity is the essence of computer programming.
User avatar
jazz_e_bob
 
Posts: 742
Joined: Tue Jul 01, 2003 9:38 pm
Location: Bloke from Cockatoo Creek Australia
Score: 14 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron