View Full Version: Where is the problem

C++ Learning Community > C++ Help > Where is the problem


Title: Where is the problem


void - January 8, 2007 07:33 PM (GMT)
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.
}


whats wrong? <_<

C-Man - January 8, 2007 09:35 PM (GMT)
works for me
perhaps this would fix it
CODE
#include <stdlib.h>
#include <stdio.h>
#include <string.h>



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

void Load(T_ **t);

int 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.
}




Hosted for free by InvisionFree