strcpy

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Freaks, See the following code below. I'm having a little trouble getting it to compile, and has usual, I don't have a clue why.

tcb_ptr->prog_id = strcpy(int8 *prog_id, int8 *program_name);

What I am trying to achieve is to copy the string array pointed to by "program_name to the new array pointed to by prog_id and return the new pointer to tcb_ptr->prog_id.
The only thing I can think of is, does the new array, "prog_id" need space allocated to it or do I have to allocate the space?
Once again, thanks for the help...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What are the "int8 *"s doing in there? Try:

tcb_ptr->prog_id = strcpy(prog_id, program_name);

And, yes, the destination MUST have allocated space. You can do:

char prog_id[20];
strcpy(prog_id, program_name);

or

char * prog_id;
prog_id=malloc(20);
strcpy(prog_id, program_name);

but do NOT be tempted to do:

char * prog_id;
strcpy(prog_id, program_name);