Advertisement

Array Question... aye

Started by March 01, 2000 10:52 PM
1 comment, last by ranxact 24 years, 9 months ago
i have been cleaning the code of my prog recently and now it seems to be giving me invalid access violations... here''s the problem.. somewhere is defined class mapper { public: char * rom; .... } later i assign a value by mapper->rom = (char *) malloc(0x8000); (inside a function) for (int i=0, i<8000; i++) (this is all symplified) mapper->rom = fgetc(file); when i return from the function i cannot access any of the values... but mapper.rom still equals the same address... essentially i cannot access array values after the function call.. (call by reference).. this should not be.. any help is appreciated... RanXacT
RanXact@yahoo.com
Its late. and i've been coding way to much recently. BUT, I would look at the following line:


for(int i=0;i<8000;i++)
mapper->rom = fgetc(file);


this probably should read

for(int i=0;i<8000;i++)
mapper->rom = (char) fgetc(file);<br></code><br><br>notice the subscript on rom… not sure if that was just a typo on your code though…<br><br>Also, fgetc() returns an integer, so you should cast it before assigning. (no clue why it returns an integer. it just does.)<br>Good luck<br><br>*oof*<br><br>Okay, nevermind that bit about the subscript. You'd think that on a programming related board, programming type code wouldn't be misread as format codes… oh well. <br><br>Edited by - Oofnish on 3/1/00 11:43:16 PM
*oof*
Advertisement
I knew it must be something stupid... but I am tired.. anyway.. about the subscript, it was a typo.. all of the initialization code was valid... my stupid mistake was that I passed my class to another function by reference in between it''s definition and it''s use. Due to a typo in that function the class was being changed.. so i fixed it and it works now... but Thank you for the help, it was driving me crazy...

As for fgetc i looked up the definition, and sure enough it returns a char in the form of an int.. (which is weird), but then again i am not loosing anything in the truncation... and the compiler isn''t complaining.. (and it works) so hey...

again ThanX for the info,
RanXacT
RanXact@yahoo.com

This topic is closed to new replies.

Advertisement