MESSAGE
DATE | 2005-01-25 |
FROM | From: "Inker, Evan"
|
SUBJECT | RE: [hangout] Simple C question
|
Check this out
strcopy.c
/* strcopy.c written by detour-at-metalshell.com * * example of a string copying function. * * http://www.metalshell.com/ * */
#include #include
void strcopy(const char *, char *);
int main() { char string1[] = "This is string1"; char string2[] = "This is string2";
strcopy(string1, string2); printf("String2: %s", string2); }
void strcopy(const char * str1, char * str2) { int x = 0;
/* change the size of string2 to the size of string1 */ realloc(str2, sizeof(str1));
do { str2[x] = str1[x]; } while (str1[x++] != '\0');
}
Regards,
Evan M. Inker (New York) x. 4615
-----Original Message----- From: Martin, Jared [mailto:JMartin-at-dglaw.com] Sent: Tuesday, January 25, 2005 2:28 PM To: hangout-at-nylxs.com Subject: [hangout] Simple C question
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)
Thank you very much
Sincerely, ***************************** Jared Martin IT Desktop Support Davis & Gilbert LLP 1740 Broadway New York, NY 10019 Help Desk: 212-237-1500 Office: 212-237-1504 Cell: 646-773-4138 Fax: (212) 974-7023 *************************************
____________________________ NYLXS: New Yorker Free Software Users Scene Fair Use - because it's either fair use or useless.... NYLXS is a trademark of NYLXS, Inc
**************************************************************************** This message contains confidential information and is intended only for the individual or entity named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. If verification is required please request a hard-copy version. This message is provided for informational purposes and should not be construed as an invitation or offer to buy or sell any securities or related financial instruments. GAM operates in many jurisdictions and is regulated or licensed in those jurisdictions as required. ****************************************************************************
____________________________ NYLXS: New Yorker Free Software Users Scene Fair Use - because it's either fair use or useless.... NYLXS is a trademark of NYLXS, Inc
|
|