|
|
Bill Cunningham wrote:
>
> Strncat is supposed
> to be better than strcat for some reason I've read.
> Is this because of a potential buffer overflow?
Probably better to read the some reason again
and then ask again if you still have questions.
> I have compiled properly and used strlen too
> and I just wonder what is the need to return a strlen?
>
> Has anyone used quite abit anyway the strlen function?
It's handy for allocations for strings.
http://www.mindspring.com/~pfilandr/C/lists_and_files/string_sort.c
tail = list_append(&head, tail, *ptr, strlen(*ptr) + 1);
www.mindspring.com/~pfilandr/C/lists_and_files/list_lib.c">http://www.mindspring.com/~pfilandr/C/lists_and_files/list_lib.c
list_type *list_append
(list_type **head, list_type *tail, void *data, size_t size)
{
list_type *node;
node = malloc(sizeof *node);
if (node != NULL) {
node -> next = NULL;
node -> data = malloc(size);
if (node -> data != NULL) {
memcpy(node -> data, data, size);
if (*head != NULL) {
tail -> next = node;
} else {
*head = node;
}
} else {
free(node);
node = NULL;
}
}
return node;
}
--
pete
|
|