strncat problem

Gerald I. Evenden gie at charon.er.usgs.gov
Tue Jul 19 09:28:41 EDT 1994


>Date: Tue, 19 Jul 94 13:19 BST-1
>From: nra at cix.compulink.co.uk (N R A  )
>Subject: strncat problem
>
>This may be teaching people to suck eggs but .....
>
>I looked in my Borland library reference and the syntax for 'strncat' was 
>listed as
>
>#include <string.h>
>char *strncat(char *dest, const char *src, size_t maxlen);
>
>and states that 
>"strncat copies at most 'maxlen' characters of 'src' to the end of 'dest' 
>and then appends a null character."
>"It is available on UNIX and is defined in ANSI C."

Your specs are ANSI C compatible, and match most traditional
C libraries, Unix and otherwise.

>Doesn't that mean that your original call was missing the 'maxlen' 
>parameter ??
>
>Steve Culshaw

Checking Bill Baker's article, the usage stated was:

>>while ((c=getchar()) && isdigit(c)) strncat(num, &c, 1);

which is syntactically OK.  What is hazy and prone to machine dependence
is the unknown declaration of c.  If it is int, then casting a char address
to c will ignore the "endian" of overlaying characters in an integer.
As I said before, there are much better and safer ways.

Gerald (Jerry) I. Evenden   Internet: gie at charon.er.usgs.gov
voice: (508)563-6766          Postal: P.O. Box 1027
  fax: (508)457-2310                  N.Falmouth, MA 02556-1027



More information about the grass-dev mailing list