Xender1
February 13th, 2012, 05:08 AM
I have a function which returns a pointer to a string of chars (max being max size in bytes)
int read_ret(char *message, int max);
read_ret(&msg, 80);
I know this msg has two strings (first name/last name each max 40 bytes), my question is how do I extract this out? I have allocated 2 other char arrays to be of size 40
char *firstname; char *lastname;
firstname = (char *) malloc(40);
lastname = (char *) malloc(40);
Should I use strncopy to but the msg into firstname/lastname, but then how do i go about using a range for lastname. Or is it as simple as assigning firstname = msg[0] and lastname=msg[41] or something like that?
Essentially I know where msg is in memory, just how do I assign firstname to equal the memory and lastname to equal the memory at the correct spot.
Thank you very much.
int read_ret(char *message, int max);
read_ret(&msg, 80);
I know this msg has two strings (first name/last name each max 40 bytes), my question is how do I extract this out? I have allocated 2 other char arrays to be of size 40
char *firstname; char *lastname;
firstname = (char *) malloc(40);
lastname = (char *) malloc(40);
Should I use strncopy to but the msg into firstname/lastname, but then how do i go about using a range for lastname. Or is it as simple as assigning firstname = msg[0] and lastname=msg[41] or something like that?
Essentially I know where msg is in memory, just how do I assign firstname to equal the memory and lastname to equal the memory at the correct spot.
Thank you very much.