A hint
You will be working with parts of arrays. The following construction is quite useful (and very common).
The idea is to pass the address of an element of an array and receive it as an array.
First in Fortran:
program main integer v(10) do k = 1, 10 v(k) = k end do print*, 'before: ', v call sub(v(5)) ! Note v(5) print*, 'after: ', v end subroutine sub(v) integer v(*) ! Note, array do k = 1, 3 v(k) = 0 end do end
When we run it we get the printout:
% a.out before: 1 2 3 4 5 6 7 8 9 10 after: 1 2 3 4 0 0 0 8 9 10 Note the zeros
Now the same thing in C:
#include <stdio.h> void sub(int []); int main() { int v[10], k; for(k = 0; k < 10; k++) v[k] = k + 1; printf("before: "); for(k = 0; k < 10; k++) printf("%d ", v[k]); sub(&v[4]); /* Note & */ printf("\nafter: "); for(k = 0; k < 10; k++) printf("%d ", v[k]); printf("\n"); return 0; } void sub(int v[]) { int k; for(k = 0; k < 3; k++) v[k] = 0; }
This is the run:
% a.out before: 1 2 3 4 5 6 7 8 9 10 after: 1 2 3 4 0 0 0 8 9 10