ambarisha.kn 15 Junior Poster in Training

Thanks Salem, I got it..

Actually i was confused with offset and address. Now i got it what is offset.

My code is working fine..
Code is as follows.
please suggest me if there is any better idea than the following code..

void create_fbeCodeDat()
{
	int checkSum=0;
	unsigned int totBufSize=0;
	vector<unsigned int>offset;
	fwrite(&signature,1, 4, bin_fp);//signature=0xabcd0001
	fwrite(&version, 1,4,bin_fp);	//Version番号
	fseek(bin_fp,4,SEEK_CUR); 	//FBDプログラムコード,	FBDパラメータサイズ
	fseek(bin_fp,2,SEEK_CUR);	     //未使用(未定義)
	fwrite(&fbdStepno,1,2,bin_fp);	//FBDステップ数[N1]
	fseek(bin_fp,4,SEEK_CUR);	//定数データへのオフセット
	fseek(bin_fp,fbdStepno*4,SEEK_CUR);	//FBDステップ オフセット	

	unsigned int fbdStepOff=fbdStepno*4;//initial constant
	offset.push_back(fbdStepOff); //Offset for FBD step 0
	
	/*ブッファにあるFB毎の実行コードの追加*/
	for(int buf=0; buf<buffList.size();++buf)
	{
                //offset for fbd steps 1 to (n-1), adding size and initial constant
		fbdStepOff+= buffList[buf].tmpAddr+4-buffList[buf].fbCodeAddr;
		offset.push_back(fbdStepOff);	
		fwrite(buffList[buf].fbCodeAddr,1,buffList[buf].tmpAddr+4-buffList[buf].fbCodeAddr, bin_fp);
		//printf("Buff FBCODEADDr:0x%x Buff tmpAdr:0x%x\n", buffList[buf].fbCodeAddr, buffList[buf].tmpAddr);
		totBufSize+=buffList[buf].tmpAddr+4-buffList[buf].fbCodeAddr;
	}
	fseek(bin_fp, -(totBufSize+fbdStepno*4), SEEK_CUR);
	for(int off=0;off<offset.size();++off)
	{	
		fwrite(&offset[off], 1,4,bin_fp);
	}
	fseek(bin_fp, totBufSize, SEEK_CUR);
	fwrite(&checkSum,1,4,bin_fp);	//sum値
}
Salem commented: Well done! +23