tcpdump mailing list archives

Re: Error in the "strcat" function


From: "Adelmo Silva" <adelmojs () hotmail com>
Date: Sat, 03 Feb 2007 17:20:49 -0200

But, if I wrote:
strcat(string1, &ips1[i]);

Another error happen:
teste1.c:294: error: incompatible types in assignment


Adelmo J. Silva





From: Guy Harris <guy () alum mit edu>
Reply-To: tcpdump-workers () lists tcpdump org
To: tcpdump-workers () lists tcpdump org
Subject: Re: [tcpdump-workers] Error in the "strcat" function
Date: Fri, 02 Feb 2007 11:35:37 -0800
MIME-Version: 1.0



That means ips1[i] is a u_char, which is an (unsigned) integer.

If you mean that you want to copy the text starting at the "i"th character in ips1 (where the first character is the 0th character), you want to do

        strcat(string1, &ips1[i]);

because

1) you want a *pointer* to the text starting at the "i"th character in ips1

and

2) you can't assign anything to string1, as it's an array, not a pointer (arrays are *NOT* pointers in C, although a reference to an array, in most but *NOT* all contexts, is converted to a pointer to the element of the array).

Note also that string1 doesn't get any bigger, as an array, so if its contents are "0123456789", ips1's contents are "abcdefghijklmnopqrstuvwxyz", and i is 5, you will overflow the string1 array.

(Note that none of this has anything to do with libpcap.)
-
This is the tcpdump-workers list.
Visit https://cod.sandelman.ca/ to unsubscribe.

_________________________________________________________________
Inscreva-se no novo Windows Live Mail beta e seja um dos primeiros a testar as novidades-grĂ¡tis. Saiba mais: http://www.ideas.live.com/programpage.aspx?versionId=5d21c51a-b161-4314-9b0e-4911fb2b2e6d

-
This is the tcpdump-workers list.
Visit https://cod.sandelman.ca/ to unsubscribe.


Current thread: