Variables in the data structure changes when they were sent to CreateRawDataBUFR at runtime. With gdb debugger, just one line before CreateRawDataBUFR, I print the value of rdi.sIdentName, rdi.sRawDataFilePath and rdi.sRawDataFileName to the screen, they are "IST" and "data/" "IST050906125859.RAWADM9" accordingly. They are true. But after i send the address of rdi to CreateRawDataBUFR, under CreateRawDataBUFR statement, i again print them with debugger. rdi.sIdentName is "IST0509061", rdi.sRawDataFilePath is "RAWADM9" , rdi.sRawDataFileName is something like "*\000\000\000\000ïÿ¿". why did they mixed each other.
Where did i do wrong?
Data structure is shown below.
typedef struct raw_data_interface
{
char sIdentName[10];
int nIdentCharLength;
char sRawDataFilePath[200];
int nFilePathCharLength;
char sRawDataFileName[200];
int nFileNameCharLength;
int nYear;
int nMonth;
int nDay;
int nHour;
int nMinute;
int nSecond;
char sDataDescriptorIdentifier[7];
char sDataDescriptorRawData[7];
}RawDataInterface;
Test.c function :
#include <stdio.h>
#include <stdlib.h>
#include <mscc.h>
#include "RawDataInterface.h"
extern void * CreateRawDataBUFR(unsigned char **, int *, char *, RawDataInterface *);
void AcquireBUFRData(RawDataInterface *, char *);
int main(int argc,char *argv[])
{
/********************************************************************************/
/* EMPRESS Initialization */
/********************************************************************************/
if(!msinit())
{
printf("msinit failed!\n");
msend();
return 1;
}
else
{
printf("msinit basarili\n");
}
int i = 0;
int * bufrSize = malloc(4);
unsigned char * ucBufrMessage = NULL;
/* RawDataInterface * rdi = malloc(sizeof * rdi); */
RawDataInterface rdi;
unsigned char * ucBinary = NULL;
char sFileName[24] = "IST050906125859.RAWADM9";
sFileName[23] = '\0';
/********************************************************************************/
/* Filling Raw Data Interface to be sent to HVFE */
/********************************************************************************/
AcquireBUFRData(&rdi,sFileName);
/********************************************************************************/
/* HVFE Trigger to create bufr message */
/********************************************************************************/
CreateRawDataBUFR(&ucBufrMessage, bufrSize, sFileName, &rdi);
free(bufrSize);
bufrSize = NULL;
free(ucBufrMessage);
ucBufrMessage = NULL;
msend();
return 0;
}
void AcquireBUFRData(RawDataInterface * rdi, char * sFileName)
{
/* Radarin adi */
char sRadarName[4];
/* Radar tarih,saat bilgisi. */
char sYear[3];
char sMonth[3];
char sDay[3];
char sHour[3];
char sMinute[3];
char sSecond[3];
strcpy(rdi->sRawDataFileName,sFileName);
rdi->nFileNameCharLength = strlen(sFileName);
strcpy(rdi->sRawDataFilePath,"data/");
rdi->nFilePathCharLength = strlen("data/");
/* Radar Name */
strncpy(sRadarName,sFileName,3);
sRadarName[3]='\0';
strncpy(sYear,sFileName+3,2);
sYear[2]='\0';
strncpy(sMonth,sFileName+5,2);
sMonth[2]='\0';
strncpy(sDay,sFileName+7,2);
sDay[2]='\0';
strncpy(sHour,sFileName+9,2);
sHour[2]='\0';
strncpy(sMinute,sFileName+11,2);
sMinute[2]='\0';
strncpy(sSecond,sFileName+13,2);
sSecond[2]='\0';
/* ASSIGNMENT TO STRUCTURE */
strcpy(rdi->sIdentName,sRadarName);
rdi->nIdentCharLength = strlen(sRadarName);
rdi->nYear = atoi(sYear);
rdi->nMonth = atoi(sMonth);
rdi->nDay = atoi(sDay);
rdi->nHour = atoi(sHour);
rdi->nMinute = atoi(sMinute);
rdi->nSecond = atoi(sSecond);
strcpy(rdi->sDataDescriptorIdentifier,"049192");
rdi->sDataDescriptorIdentifier[6] = '\0';
strcpy(rdi->sDataDescriptorRawData,"049193");
rdi->sDataDescriptorRawData[6] = '\0';
}
CreateRawDataBUFR :
void CreateRawDataBUFR(unsigned char ** ucppBUFR, int * bufrSize, RawDataInterface * rdi)
{
MAIN_DATA MainData;
/* Tam Dosya yolu */
char sRawFilePath[120];
char sTableBName[23];
char sTableCName[23];
char sTableNamesExtension[18];
char sTableNamesExtensionAfterDot[4];
........