In article <bob-EABE57.17554212022008@[EMAIL PROTECTED]
>,
Robert Peirce <bob@[EMAIL PROTECTED]
> wrote:
> I have the following definitions in a header file:
>
> /*
> Declarations for database variables
> */
>
> char t[TL]; /* ticker */
> char n[SN]; /* name */
> int g1,g2,g3; /* group codes */
>
> TL is defined as 9 and SN as 31 in another header file.
>
>
> They are used in the following code segment:
>
> fgets(s1, BUF, sd);
What are those 3 things defined as?
> strcpy(t, s1);
What happens if the string at s1 is longer than 8 bytes?
> t[TL-1] = '\0';
> printf ("Ticker = %s.\n", t); // This is correct
> printf ("Something happens between here . . .\n");
>
> strcpy(n,s1+TL); // This is tra****ng t
What do you expect to find 9 bytes after the start of s1? What happens
if that's longer than 30 characters?
> printf ("And here . . .\n");
> printf ("Ticker = %s.\n", t); // This is trash
> n[SN-1] = '\0';
>
> This code works fine under Uwin on a PC. The module compiles with no
> errors or warnings on my Intel based MacBook Pro. Something seems to be
> getting stepped on but I can't figure out how.
>
> I think I am missing something obvious. Can anybody help?
As a tip, I really recommend using more descriptive variable names.
Terseness is really not a virtue.
Also it's an excellent idea to get into the habit of initializing
variables as the point of declaration.


|