#include <stdio.h>
#include <time.h>
#include <string.h>
int main()
{
int e;
FILE *fp;
char fname[13] = "AMH_TdySales-";
This array has room for 13 "char"s. The initializer:
"AMH_TdySales-\0"
0 1
1234567890123***ran off the end here
*does* fit, just barely, by C's rule that says that the terminating
'\0' of a string literal initializer is discarded when initializing
an array whose size is just big enough to hold everything except the
'\0'.
Or, to put it another way, had you written:
char fname[] = "AMH_TdySales-";
the array would have size *14*, not 13.
The end result is that fname[] contains a sequence of bytes that
is *not* terminated with a '\0', and is therefore not a string
(by definition).
time_t rawtime;
struct tm * timeinfo;
char t[9];
The array "t" has size 9 (in "C bytes", aka chars).
rawtime = time (NULL);
timeinfo = localtime (&rawtime);
strftime(t ,10 , "%Y%m%d", timeinfo);
The array "t" has size 9. Why did you tell strftime() to write at
most *ten* characters into a 9-character array? However, %Y needs
4, %m needs 2, and %d needs 2; and 4+2+2 = 8 -- so strftime() will
write the appropriate 8 characters, then add a ninth '\0' character
to make the result a string, and this does fit.
The strncat() function needs its first argument to be a string --
a sequence of "char"s terminated by a '\0' character. fname does
not hold a string, so the effect is undefined.
Even if it were OK, this tells strncat to add at most 8 characters
to the original string. If the original string has 13 non-'\0'
characters followed by a '\0', the resulting string will have 13+8
= 21 non-'\0' characters followed by a '\0'. So it needs at least
22 bytes of space.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it
http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.