void FullPath( char *newp, char *oldp, char *ext)
{
char *p = strchr( oldp, '.' );
if (p!=NULL) *p='\0';
snprintf( newp, sizeof(newp), "%s%s", oldp, ext );
}
The sizeof operator (yes, it is an operator like + or ~) returns
the size, in C bytes (which C also calls "char"s) [%], of its
operand. Here its operand is newp, and sizeof newp is the same as
sizeof(char *), which is typically four or eight today.
You need to tell snprintf() something other than 4 or 8 -- you
need to tell it how many bytes ("char"s) it is allowed to write
into newp[0], newp[1], newp[2], ..., newp[N-1]. That is, there
is some number N that defines the size of the area to which newp
points. What is N?
(*I* do not know what N is. The FullPath() function does not
receive N as a parameter. Where *will* N come from?)
... i could use strlen() ...
The strlen() function counts the number of chars (bytes) that can
be accessed sequentially before encountering a '\0' character.
Hence if newp[0] is currently 17 and newp[1] is currently 56 and
newp[2] is currently 0 and newp[3] is currently 41, strlen(newp)
will be 2. Clearly there is little if any relationship between
strlen(newp) and the number you need (N). (Of course, we can hope
that if you do call strlen(newp), the result is strictly less than
N -- if not, strlen() went past the N characters that it is "allowed"
to inspect, and inspected s9me other character(s) that it should
not have, using out-of-bounds array subscripts.)
[% Note that a "C byte" may be more than 8 bits. Some digital
signal processor C compilers have 16-bit or 32-bit "char"s. These
are still "bytes", on those machines, in the C language. To talk
about something that is always exactly 8 bits, networking folks
use the word "octet", to distinguish it from the 9 and 10 bit bytes
found on Univac and BBN-C-machines, and so on.]