Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Mac > Mac Programmer > Re: Something i...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 12 Topic 995 of 1040
Post > Topic >>

Re: Something is stepping on something

by Robert Peirce <bob@[EMAIL PROTECTED] > Feb 13, 2008 at 02:41 AM

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); 
>         
>         strcpy(t, s1); 
>         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
> 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?

I just thought of something you Apple experts might know.  This has 
always worked before because t came in memory before n.  I am copying 
s1+TL to n, which is bout 150 characters into a 31 character string.  It 
is going to trash anything that follows it in memory, which has never  
been a problem because n always followed t.  While this is probably a 
really dumb assumption, it has worked for 20 years.  However, does that 
actually happen in this case?  If t follows n in memory, it would 
explain why t is getting trashed.  It wouldn't quite explain exactly 
what is getting into t, but it would be a start.

-- 
Robert B. Peirce, Venetia, PA  724-941-6883
bob AT peirce-family.com [Mac]
rbp AT cooksonpeirce.com [Office]
 




 12 Posts in Topic:
Something is stepping on something
Robert Peirce <bob@[EM  2008-02-12 22:55:42 
Re: Something is stepping on something
Reinder Verlinde <rein  2008-02-13 00:19:07 
Re: Something is stepping on something
Robert Peirce <bob@[EM  2008-02-13 02:19:37 
Re: Something is stepping on something
Gregory Weston <uce@[E  2008-02-12 20:37:55 
Re: Something is stepping on something
Sean McBride <cwatson@  2008-02-12 21:34:38 
Re: Something is stepping on something
Robert Peirce <bob@[EM  2008-02-13 02:41:00 
Re: Something is stepping on something
Robert Peirce <bob@[EM  2008-02-13 02:48:56 
Re: Something is stepping on something
Paul Russell <prussell  2008-02-13 09:51:12 
Re: Something is stepping on something
Robert Peirce <bob@[EM  2008-02-14 14:12:00 
Re: Something is stepping on something
Paul Russell <prussell  2008-02-14 14:23:31 
Re: Something is stepping on something
Robert Peirce <bob@[EM  2008-02-14 17:36:16 
Re: Something is stepping on something
Reinder Verlinde <rein  2008-02-14 18:43:59 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 9:53:39 CST 2008.