View Single Post
Join Date: Jun 2008
Posts: 66
Reputation: ambarisha.kn is an unknown quantity at this point 
Solved Threads: 0
ambarisha.kn ambarisha.kn is offline Offline
Junior Poster in Training

Re: Help: fwrite, I want to write forward pointer address in present file pointer

 
0
  #7
Oct 23rd, 2008
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..
  1. void create_fbeCodeDat()
  2. {
  3. int checkSum=0;
  4. unsigned int totBufSize=0;
  5. vector<unsigned int>offset;
  6. fwrite(&signature,1, 4, bin_fp);//signature=0xabcd0001
  7. fwrite(&version, 1,4,bin_fp); //Version番号
  8. fseek(bin_fp,4,SEEK_CUR); //FBDプログラムコード, FBDパラメータサイズ
  9. fseek(bin_fp,2,SEEK_CUR); //未使用(未定義)
  10. fwrite(&fbdStepno,1,2,bin_fp); //FBDステップ数[N1]
  11. fseek(bin_fp,4,SEEK_CUR); //定数データへのオフセット
  12. fseek(bin_fp,fbdStepno*4,SEEK_CUR); //FBDステップ オフセット
  13.  
  14. unsigned int fbdStepOff=fbdStepno*4;//initial constant
  15. offset.push_back(fbdStepOff); //Offset for FBD step 0
  16.  
  17. /*ブッファにあるFB毎の実行コードの追加*/
  18. for(int buf=0; buf<buffList.size();++buf)
  19. {
  20. //offset for fbd steps 1 to (n-1), adding size and initial constant
  21. fbdStepOff+= buffList[buf].tmpAddr+4-buffList[buf].fbCodeAddr;
  22. offset.push_back(fbdStepOff);
  23. fwrite(buffList[buf].fbCodeAddr,1,buffList[buf].tmpAddr+4-buffList[buf].fbCodeAddr, bin_fp);
  24. //printf("Buff FBCODEADDr:0x%x Buff tmpAdr:0x%x\n", buffList[buf].fbCodeAddr, buffList[buf].tmpAddr);
  25. totBufSize+=buffList[buf].tmpAddr+4-buffList[buf].fbCodeAddr;
  26. }
  27. fseek(bin_fp, -(totBufSize+fbdStepno*4), SEEK_CUR);
  28. for(int off=0;off<offset.size();++off)
  29. {
  30. fwrite(&offset[off], 1,4,bin_fp);
  31. }
  32. fseek(bin_fp, totBufSize, SEEK_CUR);
  33. fwrite(&checkSum,1,4,bin_fp); //sum値
  34. }
Ambarish
Reply With Quote