On Suday the 11th of February, 2007 -after 3 and a half years on InvisionFree, we have moved! This old board remains as a read only archive of years past, and registration has been disabled here. All new and current members should register at http://www.cpplc.net/forum .


InvisionFree - Free Forum Hosting
Free Forums with no limits on posts or members.

Learn More · Register for Free
Welcome to C++ Learning Community. We hope you enjoy your visit.


You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Name:   Password:

Please help out
Google

  Reply to this topicStart new topicStart Poll

> Whats wrong?
void
Posted: Jan 8 2007, 07:37 PM
Quote Post


N00b!!!


Group: Members
Posts: 2
Member No.: 2,390
Joined: 8-January 07



CODE
#include <stdlib.h>
#include <stdio.h>
#include <string.h>



struct T_{
char fName[10];
   char tName[10];
};

void Load(T_ **t);

void main()
{
 T_ *t;
 Load( &t );
 printf( "Data: %s\n", t[0].fName );
 scanf( "%s" );

}


void Load(T_ **t)
{
*t = new T_[10];
strcpy( (*t[0]).fName, "Name" );
strcpy( (*t[1]).fName, "Name2" ); //0xC0000005: Access violation writing location 0xcccccccc.
}


PMEmail Poster
Top
myork
Posted: Jan 8 2007, 08:58 PM
Quote Post


c++ guru


Group: Super Moderator
Posts: 2,584
Member No.: 487
Joined: 21-January 04



QUOTE (void @ Jan 8 2007, 02:37 PM)
CODE
#include <stdlib.h>
#include <stdio.h>
#include <string.h>



struct T_{
char fName[10];
   char tName[10];
};

void Load(T_ **t);

void main()
{
 T_ *t;
 Load( &t );
 printf( "Data: %s\n", t[0].fName );
 scanf( "%s" );

}


void Load(T_ **t)
{
*t = new T_[10];
strcpy( (*t[0]).fName, "Name" );
strcpy( (*t[1]).fName, "Name2" ); //0xC0000005: Access violation writing location 0xcccccccc.
}


I think (though I need to test).
That the operator [] behinds tighter than the operator *.

Thus:
CODE
(*t[1]).fName

is equivelant to:

(*(t[1])).fName

So you may want to add braces appropriately:

((*t)[1]).fname
PMEmail Poster
Top
« Next Oldest | C++ Help | Next Newest »
DealsFor.me - The best sales, coupons, and discounts for you

Topic Options Reply to this topicStart new topicStart Poll


Skin selector developed by XJONX. Skins created by various members of the IF Skin Zone and InvisionFree Skinning

Please help out
Hosted for free by InvisionFree* (Terms of Use: Updated 2/10/2010) | Powered by Invision Power Board v1.3 Final © 2003 IPS, Inc.
Page creation time: 0.0814 seconds | Archive