Characters pointer 's address changing
i am new to here
i am confused about the const char pointer
here is the code:
int main()
{
const char map[12][24];
char fileName[] = "map1.txt";
const char * mPtr;
mPtr = map;
printf( "%d %d \n", mPtr, map );
load_map( fileName, map );
printf( "%d %d \n", mPtr, map );
return 0;
}
Here are the load_map function code:
bool load_map( char * fileName, char * map )
{
FILE * fptr;
char c;
int count = 0;
fptr = fopen( fileName, "r" );
if( fptr == NULL ) {
printf( "Fail to read map \n" );
return false;
}
do {
c = fgetc( fptr );
*( map + count++ ) = c;
if ( count % 23 == 0 ) continue;
*( map + count++ ) = ' ';
} while( c != EOF );
fclose( fptr );
}
my question is when execute
mPtr = map;
and they exactly with the same memory address
but after the load_map() funtion executed
mptr's address changed
but in that function, i do not referenced to mptr
i am really confused why it change
it's my first post, bad formatting skill, please forgive me :)
No comments:
Post a Comment