|
Post by alexfish on Dec 25, 2020 3:21:04 GMT 1
Hi All although not tested with bacon as yet loding a file; since been a few weeks trying to find the F******G bug the bug close(file); this will corrupt the stack, as fix I just found that free(file) will work for now: sorry for the c code: but time is passed 12 here and think my ears will be burning in a few hours the c code void load ( char *filename){ FILE *f = fopen(filename, "r"); fseek(f, 0, SEEK_END); long fsize = ftell(f); fseek(f, 0, SEEK_SET); /* same as rewind(f); */ //* sizeof(char) char *str=(char*) malloc(fsize* sizeof(char*)); fread(str, 1, fsize, f); //close(f); free(f); puts( str); free (str); //str[fsize] = 0; } tested with valgrind:: Good Tidings to You All; + BR Alex
|
|
|
Post by Pjot on Dec 25, 2020 9:32:51 GMT 1
Hi Alex, If you open a file using 'fopen' then you have to use ' fclose' to close the file handle. HTH Peter
|
|
|
Post by alexfish on Dec 25, 2020 10:11:50 GMT 1
Hi Peter have tried the fclose , same seg fault I am still playing with the bits , have found if do a fseek(f, 0, SEEK_END); and the 'fclose' the file it fails when returns to to other functions in the program. if do fseek(f, 0, SEEK_SET); it passes: at present no read is done, as to why the SEEK_END ? although bacon load and the traditional read line are good while I am here , is there a currency feature in bacon have tested this PROTO setlocale setlocale(LC_NUMERIC, "") PRINT 2000567.89 FORMAT " %'15.2Lf" BR Alex
|
|
|
Post by alexfish on Dec 25, 2020 16:52:05 GMT 1
Ah well
found the segfault, I think says he
in a different routine: looks like got a mix up on new string , used malloc and then strcat and should have used strcpy:
time will tell.
strange that the app was working untill I used the load file. + if I free the file ,free(f) instead of close or fclose(f); it will work
I hate C.
BR Alex
|
|
|
Post by Pjot on Dec 27, 2020 14:27:26 GMT 1
That makes two of us Regards Peter
|
|