Having trouble with "ftell()"
ronsherr
Posts: 2
Hi there!
I'm hoping that someone can point me in the right direction.
I'm not getting expected return from ftell()...it always returns zero on my system.
I've put together the following simplistic example:
Am I doing this wrong?
Thanks in advance,
Ron
I'm hoping that someone can point me in the right direction.
I'm not getting expected return from ftell()...it always returns zero on my system.
I've put together the following simplistic example:
#include "simpletools.h" #define SDDO 22 #define SDCLK 23 #define SDDI 24 #define SDCS 25 int main() { char textForFile[] = "Testing 123...Add extra data...\n"; char s[15], t[15]; unsigned long position; sd_mount(SDDO,SDCLK,SDDI,SDCS); print("Open file for writing\n"); FILE* fp = fopen("new1.raw", "wb"); if(fp==NULL){print("ERROR opening file fro Write\n");} print("Write to file\n"); fwrite(textForFile,1,sizeof(textForFile),fp); print("Closing file\n"); fclose(fp); fp = NULL; print("Opening file for Read\n"); fp = fopen("new1.raw","rb"); if(fp==NULL){print("ERROR opening file for Read\n");} position = ftell(fp); printf("Current position is %lu \n",position); fread(s, 1, 15, fp); printf("Reading file data: %s \n",s); fseek(fp, 0, SEEK_END); print("Seeking to end\n"); position = ftell(fp); printf("Now current position is %lu \n",position); //On my system I get zero here? fread(t, 1, 15, fp); printf("Reading file data: %s \n",t); //shouldn't get good data here...I'm past END print("Rewinding\n"); rewind(fp); fread(t, 1, 15, fp); printf("Read file data after rewind: %s \n",t); //Now I get good data, which is correct. while(1) { } }
Am I doing this wrong?
Thanks in advance,
Ron
Comments
I seem to have replicated the problem here. I changed the code up to check for errors along the way. here's the results:
Which is a result of this code:
Sorry... you've written your code correctly, but this is a bug/not-yet-written-piece in PropGCC.
Thanks very much for your time/help!
If I understand you correctly, I should file this as a bug against propgcc on the code.google.com project site?
Yep, that would be good. If/when a fix gets committed, let me know and I'll rebuild the versions of PropGCC on my site.
David, I plan on checking it into the default branch. Are there any other branches that I should add it to?
Thanks for fixing this! Yes, you should probably also add it to the release_1_0 branch because that is what is currently used in the SimpleIDE releases.
Thanks,
David