RadarData * rd = NULL;
rd = GetRadarData(sFileName);
/*
Here the debugger says that :
rdp->llBdContent.bdContent.next = 0xa13f080.
This is ok,but...
*/
CreateHVFERadarBUFR(&rd);
GetRadarData is here:
RadarData * GetRadarData(char * sFileName)
{
short int nRadarSubtypeInFile;
short int nRadarTypeInFile;
/* Radar Data Structure */
RadarData rd;
/* Radarin adi */
char * sRadarName = (char *) malloc(4);
/* Radar tarih,saat bilgisi. */
char * sYear = (char *) malloc(2);
char * sMonth = (char *) malloc(2);
char * sDay = (char *) malloc(2);
char * sHour = (char *) malloc(2);
char * sMinute = (char *) malloc(2);
char * sSecond = (char *) malloc(2);
rd.sRadarName = (char *) malloc(4);
rd.llBdContent.bdContent.data = (char *) malloc(MAXSIZE);
rd.llBdContent.bdContent.next = NULL;
/* Radar Name */
sRadarName = strncpy(sRadarName,sFileName,3);
sYear = strncpy(sYear,sFileName+3,2);
sMonth = strncpy(sMonth,sFileName+5,2);
sDay = strncpy(sDay,sFileName+7,2);
sHour = strncpy(sHour,sFileName+9,2);
sMinute = strncpy(sMinute,sFileName+11,2);
sSecond = strncpy(sSecond,sFileName+13,2);
/* ASSIGNMENT TO STRUCTURE */
rd.sRadarName = strcpy(rd.sRadarName,sRadarName);
rd.sRadarName = strcat(rd.sRadarName,"1");
rd.ddYearMonthDay.nYear = atoi(sYear);
rd.ddYearMonthDay.nMonth = atoi(sMonth);
rd.ddYearMonthDay.nDay = atoi(sDay);
rd.dtHourMinuteSecond.nHour = atoi(sHour);
rd.dtHourMinuteSecond.nMinute = atoi(sMinute);
rd.dtHourMinuteSecond.nSecond = atoi(sSecond);
nRadarSubtypeInFile = GetRdbSubtype(rd.sRadarName);
rd.nRdbSubtype = nRadarSubtypeInFile;
nRadarTypeInFile = GetRdbType(rd.sRadarName);
rd.nRdbType = nRadarTypeInFile;
free(sRadarName);
sRadarName = NULL;
free(sYear);
sYear = NULL;
free(sMonth);
sMonth = NULL;
free(sDay);
sDay = NULL;
free(sHour);
sHour = NULL;
free(sMinute);
sMinute = NULL;
free(sSecond);
sSecond = NULL;
/* Bulk Data buradan itibaren okunup, long size, char data[] bilgisi giriliyor. */
SetBulkData(&rd,sFileName);
return &rd;
}
void SetBulkData(RadarData * rd, char * sFileName)
{
int nFileSize;
LLBulkData * llBulkDataDummy = NULL;
LLBulkData * llBulkDataDummy2 = NULL;
BulkData * bdDummy = NULL;
int nMaxByteCount = MAXSIZE * 1000000;
double dBulkDataCount;
int nLastBulkDataSize;
int nBulkDataCount = 0;
int nDummyFileSize = 0;
/* Tam Dosya yolu */
char * sRawFilePath = (char *) malloc(120);
/* fopen source */
char * sFile = (char *) malloc(200);
int i;
FILE * DataFile = NULL;
char * caFileContent = (char *) malloc(nMaxByteCount);
char * sDummyFileContentFirst = (char *) malloc(MAXSIZE);
char * sDummyFileContent = NULL;
int nAdditiveBulk = 0;
sRawFilePath = strcpy(sRawFilePath,"data/");
sFile = strcat(sRawFilePath,sFileName);
DataFile = fopen(sFile,"rb");
if(DataFile == NULL)
printf("DataFile NULL\n");
nFileSize = fread(caFileContent,sizeof(char),nMaxByteCount,DataFile);
nDummyFileSize = nFileSize;
fclose(DataFile);
dBulkDataCount = nDummyFileSize / MAXSIZE;
nBulkDataCount = (int) dBulkDataCount;
if(nDummyFileSize % MAXSIZE > 0)
nBulkDataCount ++ ;
nLastBulkDataSize = nMaxByteCount % MAXSIZE;
for(i=0; i<nBulkDataCount; i++)
{
if(i==0)
{
llBulkDataDummy = &rd->llBdContent;
memcpy(sDummyFileContentFirst,caFileContent,MAXSIZE);
bdDummy = (BulkData *) CreateNewBulkDataNode();
memcpy(bdDummy->data,sDummyFileContentFirst,MAXSIZE);
AssignRootOfLinkedList(&llBulkDataDummy,&bdDummy);
llBulkDataDummy->size = 1;
nDummyFileSize = nDummyFileSize - MAXSIZE;
free(sDummyFileContentFirst);
sDummyFileContentFirst = NULL;
}
else
{
sDummyFileContent = (char *) EraseCopiedBytes(caFileContent+i*MAXSIZE, nDummyFileSize);
if(sDummyFileContent == NULL)
break;
bdDummy = (BulkData *) CreateNewBulkDataNode();
memcpy(bdDummy->data,sDummyFileContent,MAXSIZE);
AddBulkDataToLinkedList(&llBulkDataDummy,bdDummy);
free(bdDummy);
bdDummy = NULL;
nDummyFileSize = nDummyFileSize - MAXSIZE;
free(sDummyFileContent);
sDummyFileContent = NULL;
sDummyFileContent = realloc(sDummyFileContent,nDummyFileSize-MAXSIZE);
}
}
nAdditiveBulk = nDummyFileSize;
printf("nAdditiveBulk = %d\n",nAdditiveBulk);
if(nLastBulkDataSize > 0)
{
bdDummy = (BulkData *) CreateNewBulkDataNode();
memcpy(bdDummy->data,sDummyFileContent,nLastBulkDataSize);
realloc(bdDummy->data,nAdditiveBulk);
}
free(sFile);
sFile = NULL;
free(caFileContent);
caFileContent = NULL;
PrintLinkedList(&llBulkDataDummy);
}
void AssignRootOfLinkedList(LLBulkData ** llBulkDest, BulkData ** bdSource)
{
LLBulkData * llBulkDummy = NULL;
BulkData * bdDummy = NULL;
BulkData * bdDummy2 = NULL;
llBulkDummy = *llBulkDest;
bdDummy = &llBulkDummy->bdContent;
bdDummy2 = *bdSource;
bdDummy2->next = NULL;
bdDummy->next = *bdSource;
*bdSource = NULL;
llBulkDummy = NULL;
bdDummy = NULL;
bdDummy2 = NULL;
}
void AddBulkDataToLinkedList(LLBulkData ** llBulk, BulkData * bdNode)
{
LLBulkData * llBulkDummy = NULL;
int i;
int nCounter = 0;
BulkData * bdDummy = NULL;
BulkData * bdWaitingToBeCopied = (BulkData *) malloc(16);
bdWaitingToBeCopied->data = (char *) malloc(MAXSIZE);
bdWaitingToBeCopied->next = NULL;
llBulkDummy = *llBulk;
memcpy(bdWaitingToBeCopied,bdNode,sizeof(bdNode));
printf("(Radar.c)(AddBulkDataToLinkedList) evet1\n");
for(bdDummy = llBulkDummy->bdContent.next; bdDummy->next != NULL; bdDummy = bdDummy->next)
{
nCounter ++;
}
bdDummy->next = bdWaitingToBeCopied;
bdWaitingToBeCopied = NULL;
bdDummy = NULL;
printf("(Radar.c)(AddBulkDataToLinkedList) evet2\n");
llBulkDummy->size++;
}
char * EraseCopiedBytes(char * caFileContent, int nSize)
{
int i;
int nNewSize = nSize;
if(nNewSize == 0)
return NULL;
char * caFileContentNew = (char *) malloc(nNewSize);
memcpy(caFileContentNew,caFileContent,nNewSize);
return caFileContentNew;
}
BulkData * CreateNewBulkDataNode()
{
BulkData * bdDummy = (BulkData *) malloc(sizeof(BulkData));
bdDummy->data = (char *) malloc(MAXSIZE);
bdDummy->next = NULL;
return bdDummy;
}
LLBulkData * CreateBulkDataLinkedList()
{
LLBulkData * llBdDummy = (LLBulkData *) malloc(sizeof(LLBulkData));
llBdDummy->bdContent.next = NULL;
llBdDummy->size = 0;
return llBdDummy;
}
CreateHVFERadarBUFR function:
void CreateHVFERadarBUFR(RadarData ** rd)
{
RadarData * rdp = * rd;
/*
Here the debugger says that :
rdp->llBdContent.bdContent.next = 0x40a13f080.
*/
BulkData * bdDummy = NULL;
bdDummy = rdp->llBdContent.bdContent.next;
printf("%s\n",rdp>llBdContent.bdContent.next->data);
/* So I get segmentation fault here
Cannot access memory at address 0x40a13f080
*/
}
Structures:
typedef struct bulk_data
{
char * data;
struct bulk_data * next;
}BulkData;
typedef struct ll_bulk_data
{
long size;
BulkData bdContent;
}LLBulkData;
typedef struct radar_data
{
char * sRadarName;
DataDate ddYearMonthDay;
DataTime dtHourMinuteSecond;
LLBulkData llBdContent;
short int nRdbType;
short int nRdbSubtype;
}RadarData;
Why does the address of BulkData structure in the RadarData change from "0xa13f080" to "0x40a13f080" ?
Thank you.