ken
ken

Reputation: 293

Error with strcpy and strcat

All im trying to do is add a string to strcpy and concatenate with a short. But i am getting two error doing this the code is below

struct local_stack_def
  {

   char *result;
   char delims[3];
   char user_id_E[200];
   short user_maxlen, range_eulm, imp_eulm, len_eulm;
   char msg_eulm[400];
   /*MORE VARIABLE REMOVED TO SHORTEN LENGTH*/
  };

  short  pool_err;
  struct local_stack_def *l;


  l  = POOL_GETSPACE_(i_exit_cb->Pool_addr,sizeof(struct local_stack_def),&pool_err );


    /*MORE VARIABLE REMOVED TO SHORTEN LENGTH*/

  if (l->resultFR != 0)
     {
      l->range_eulm= 1501;
      strcpy(l->msg_eulm,"FILENAME_RESOLVE_ ERROR - ERROR#:");
      strcat(l->msg_eulm, l->resultFR);

With the strcpy and strcat i get these errors

strcpy(l->msg_eulm,"FILENAME_RESOLVE_ ERROR - ERROR#:");     
 Warning 207: address pointing at code space is taken

 strcat(l->msg_eulm, l->resultFR);
 Warning 86: argument 2 conflicts with formal definition

Upvotes: 3

Views: 588

Answers (3)

Both functions work on char* types. When you use strcpy on some constant string you defined, this string is located in code space which could be a problem, hence the warning.

The second error is caused because you cannot concat an integer to a string. When you want to print the value of this short you need to convert it for example via sprintf into an char* and than concat this char*.

Upvotes: 1

pm100
pm100

Reputation: 50110

for the concatenate you need to either use itoa (or one of its variants)

strcat(l->msg_eulm, itoa(l->resultFR));

If you dont have itoa in you c library then you could use snprintf.OR look for another function that takes a number and returns a char*

Upvotes: 1

Šimon Tóth
Šimon Tóth

Reputation: 36423

You didn't provide information about resultFR (which obviously isn't const char*).

You also didn't provide information about what compiler you are using, but from the documenation on web:

Warning 207: The address of an object that resides in code space is taken. Use of this address is valid only within the same code segment as the object.

Upvotes: 1

Related Questions