Ver Mensaje Individual
  #1 (permalink)  
Antiguo 17/12/2008, 06:53
allypooh19
 
Fecha de Ingreso: diciembre-2008
Mensajes: 5
Antigüedad: 15 años, 5 meses
Puntos: 0
Problemas con asignar memoria a estructuras

Hola a todos.

Tengo el siguiente problema. He definido una estructura en un fichero de la siguiente forma:

#define MAX_FILES 100

typedef struct Transfer {
char * fileNames;
int * operationsFiles;
}Transfer,*TransferPtr;
En el primer metodo

//Init the struc
TransferPtr tfr = (TransferPtr)calloc(1,sizeof(Transfer));
tfr->fileNames = (char *)calloc(MAX_FILES, sizeof(char));
tfr->operationsFiles = (char *)calloc(MAX_FILES, sizeof(char));
printf("[VALORES DE STRUCT]\n %p",tfr->operationFiles[0]);


El problema está en que hago lo siguiente:

int index = 0;
tfr->fileNames[index] = fileSource;
printf("[OPS] %s",fileSource); --> Imprime file_0000
tfr->operationsFiles[index] = 1;
printf("[OPF] %s",transfer->fileNames[index]); -->Devuelve SEGMENTATION_FAULT


No entiendo porque esta operación devuelve Segmentation Fault.¿Me podeis ayudar?

Muchas gracias