-
void hi ( int *b, FILE *pfile ) { rewind ( pfile ); int i; for( i = 0 ; i < 3 ; i++ ) { fscanf ( pfile, "%d", &b[i] ); } } int main ( void ) { FILE *fp = fopen ( "test.txt", "r" ); int a[10];
I am trying to understand pointers when an array is involved. While I was testing the above code, I noticed that by adding another index value, for example hi ( &a[0], fp ) to hi ( &a[1], fp ) , I get different results.
//result of [ hi ( &a[0], fp ) ] //result of [ hi ( &a[1], fp ) ] 50,13,124 junk#,50,13 .
I really got confused in the results, because in the "hi" function I specify the beginning of an array of i = 0 , which should mean that it stores a value starting with a[0] . But it seems that put 1 instead of 0 somehow moves the values ββto the side. Why is this happening?
c function arrays pointers
Chewhew
source share