MESSAGE
DATE | 2005-01-25 |
FROM | Billy
|
SUBJECT | Re: [hangout] Simple C question
|
James Linder wrote: > > On Tuesday 25 January 2005 03:21 pm, Inker, Evan wrote: > >>Check this out >> >>strcopy.c >> >>.............. >> >> >>If I have three strings: >>char *str1; >>char str2[]; >>char str3[10]; >> >>how do I copy the info from str1 to str2? >> >>how do I copy the info from str1 to str3? (I imagine it is the same, and I >>realize I will loose data if strlen(str1)>10)
> Watch out using strcopy for copying str1 to str3. From what I understand > it'll keep writing after the end of the str3 array. I think there is an > nstrcopy() function you could use too that you can tell exactly how many > elements to copy from one char array to another.
that's strcpy() and strncpy(), not strcopy() and nstrcopy().
'man string' for more juicy details.
You're much better off using strcpy than using your own implementation, btw. The built-in version from #include is going to be written is super-optimized assembly (IIRC there's a single IA32 opcode to do strcpy). ____________________________ NYLXS: New Yorker Free Software Users Scene Fair Use - because it's either fair use or useless.... NYLXS is a trademark of NYLXS, Inc
|
|