| | |
Help: fwrite, I want to write forward pointer address in present file pointer
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2008
Posts: 66
Reputation:
Solved Threads: 0
I wrote the following function and it is working fine, but my problem is i want to write forward pointer address in present pointer field.
I will explain in code.
please check line numbers 10, 11, 12, 13 in the following code..
I will explain in code.
please check line numbers 10, 11, 12, 13 in the following code..
c Syntax (Toggle Plain Text)
void create_fbeCodeDat() { int checkSum=0; fwrite(&signature,1, 4, bin_fp);//signature=0xabcd0001 fwrite(&version, 1,4,bin_fp);//Version番号 fseek(bin_fp,4,SEEK_CUR); //FBD Program code fseek(bin_fp,2,SEEK_CUR); //not used fwrite(&fbdStepno,1,2,bin_fp); //FBD step No.[N1] fseek(bin_fp,4,SEEK_CUR); //const data offset //Here i have to write the address of next fbdstepno*4+1 bytes //consider fbdstepno=4, here in 4 bytes have to write address of 5th byte address // for ex: next 5th byte adress has to be write here in 4 bytes //fwrite( addr(5th byte), 1,4, bin_fp); //how to write 1st argument // actually in the program here i have to write the address of buffList[buf].fbCodeAddr in 4 bytes. for buf=0, have to write bufflist[0].fbCodeAddr in 4 bytes // for buf=0 and 1, have to write bufflist[0].fbCodeAddr in 4 bytes, and bufflist[1].fbCodeAddr in 4 bytes //and so on... and next the following code continues.. for(int buf=0; buf<buffList.size();++buf) { fwrite(buffList[buf].fbCodeAddr,1,buffList[buf].tmpAddr+4-buffList[buf].fbCodeAddr, bin_fp); } fwrite(&checkSum,1,4,bin_fp);//sum値 }
Last edited by ambarisha.kn; Oct 22nd, 2008 at 1:51 am.
Ambarish
Re: Help: fwrite, I want to write forward pointer address in present file pointer
1
#2 Oct 22nd, 2008
>i want to write forward pointer address in present pointer field.
If I understand your problem correctly, you have two immediate options:
If I understand your problem correctly, you have two immediate options:
- Get the current address, then offset it by the known amount and write it.
- Seek forward, save the current address, then seek back and write it.
I'm here to prove you wrong.
Re: Help: fwrite, I want to write forward pointer address in present file pointer
0
#3 Oct 22nd, 2008
•
•
Join Date: Jun 2008
Posts: 66
Reputation:
Solved Threads: 0
Re: Help: fwrite, I want to write forward pointer address in present file pointer
0
#4 Oct 22nd, 2008
•
•
•
•
>i want to write forward pointer address in present pointer field.
If I understand your problem correctly, you have two immediate options:
- Get the current address, then offset it by the known amount and write it.
- Seek forward, save the current address, then seek back and write it.
How to get the current address
Ambarish
•
•
Join Date: Jun 2008
Posts: 66
Reputation:
Solved Threads: 0
Re: Help: fwrite, I want to write forward pointer address in present file pointer
0
#5 Oct 22nd, 2008
Re: Help: fwrite, I want to write forward pointer address in present file pointer
0
#6 Oct 23rd, 2008
It's an array of offsets into the file, not addresses as such.
Since you know how many there are, you can calculate the size of this table, and populate it with what the effective start positions of each buffList[buf].fbCodeAddr will be written to (it's just an initial constant, and a sum of lengths)
Oh, and try to use portable image formats in future.
Since you know how many there are, you can calculate the size of this table, and populate it with what the effective start positions of each buffList[buf].fbCodeAddr will be written to (it's just an initial constant, and a sum of lengths)
Oh, and try to use portable image formats in future.
•
•
Join Date: Jun 2008
Posts: 66
Reputation:
Solved Threads: 0
Re: Help: fwrite, I want to write forward pointer address in present file pointer
1
#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..
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..
C Syntax (Toggle Plain Text)
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値 }
Ambarish
![]() |
Other Threads in the C Forum
- Previous Thread: Retrieving a paragraph instead of a single line of text
- Next Thread: Help with C code
| Thread Tools | Search this Thread |
#include * ansi append array arrays asterisks bash binarysearch centimeter changingto char character convert copyimagefile cprogramme creafecopyofanytypeoffileinc createprocess() database dynamic execv fgets file floatingpointvalidation fork framework function getlogicaldrivestrin givemetehcodez grade gtkwinlinux hacking histogram ide inches include infiniteloop initialization input interest intmain() iso kernel keyboard kilometer km license linked linkedlist linux list lists looping lowest matrix meter microsoft number oddnumber open opendocumentformat openwebfoundation overwrite owf pdf pointer pointers posix power probleminc process program programming radix recursion recv recvblocked research reversing segmentationfault sequential single socket socketprogramming standard strchr string suggestions systemcall test testing threads turboc unix urboc user variable wab whythiscodecausesegmentationfault windowsapi






