Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > strcat strncat and strlen

Reply
Thread Tools

strcat strncat and strlen

 
 
santosh
Guest
Posts: n/a
 
      03-31-2008
Bartc wrote:

>
> "santosh" <(E-Mail Removed)> wrote in message
> news:fspevv$2e1$(E-Mail Removed)...
>> Bill Cunningham wrote:
>>
>>>> You are not making any sense. Are you asking why strlen exists? It
>>>> should be obvious, even to you. How else do you find the length of
>>>> a zero terminated string?
>>>
>>> C must not count '\0' as being part of a string.

>>
>> It is a part of a C string. However it is not counted by strlen.
>>
>>> This is the simple code I tried,
>>>
>>> int main(void) {
>>> size_t t;
>>> char hello[]="hello world\n";
>>> t=strlen(hello);
>>> printf("%i",hello);

>>
>> The format for size_t is %zu. If your compiler does not support this
>> then the next best method is to use %lu and cast it's argument to
>> unsigned long.

>
> Printing the value of hello instead of t has a bigger effect than
> using the wrong format spec.


Oops. Yes, another case of reading what I expected to read I suppose. In
which case the output that the OP mentioned is wrong. I think this
proves finally that the OP *is* a troll.

 
Reply With Quote
 
 
 
 
santosh
Guest
Posts: n/a
 
      03-31-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> On Mar 31, 3:47 am, santosh <(E-Mail Removed)> wrote:
>> Bill Cunningham wrote:
>> > Strncat is supposed to be better than strcat for some
>> > reason I've read.

>>
>> It does something different to what it's name would suggest. We have
>> had innumerable threads dealing with this topic. Just do a Google
>> search.
>>
>> > Is this because of a potential buffer overflow?

>>
>> Well, it can be used with that aim, in which case it leaves an array
>> of char instead of a string in the destination.
>>
>> > 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?

>>
>> You are not making any sense. Are you asking why strlen exists? It
>> should be obvious, even to you. How else do you find the length of a
>> zero terminated string?

>
> Can you or someone else please explain why everyone is still replying
> to this "Bill Cunningham' troll?
> It's clear he is a troll.


I was doubtful for a while, but I believe you are right. In any case,
even if he were not a troll, he seems to be unable to learn, so
replying to him seems increasingly pointless.

> It's been noted countless times and he
> *never* replies to the posts that call him a troll.
> He always choses to take things out of context, to make
> uncomprehensible sentences and ambiguous statements.
> It's a troll. So.. why?


It was a case of "cutting him some slack" as Richard said. Bill has been
cut more slack than probably anyone else, but personally I'm done with
him.

 
Reply With Quote
 
 
 
 
Bill Cunningham
Guest
Posts: n/a
 
      03-31-2008

> It's handy for allocations for strings.
>
> http://www.mindspring.com/~pfilandr/.../string_sort.c
>
> tail = list_append(&head, tail, *ptr, strlen(*ptr) + 1);
>
>
> http://www.mindspring.com/~pfilandr/...les/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;
> }
>


Thanks Pete. I have found a book called "Algorithms in C" that might be
what I'm looking for.

Bill


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
strncat functionality Kelvin Moss C Programming 4 01-25-2005 09:47 AM
strncat copies junk values .... Vaddina Prakash Rao C Programming 11 12-28-2004 12:22 PM
strncat copies junk values .... Vaddina Prakash Rao C Programming 4 12-21-2004 12:43 PM
Two Questions about "strlen", "strcat" and "strcpy" Matt C Programming 82 09-29-2004 12:26 PM
strcpy and strcat problem JC C Programming 23 09-29-2003 04:27 PM



Advertisments