Passing arguments in c functions
I'm newbie in c. I have written a function in c and passes the arguments
to it but I got different answers as I expect.
The function is
void GridDim(float long1, float long2, float dx,
float lat1, float lat2, float dy,
float depth1, float depth2, float dh,
int *m, int *n, int *k)
{
*m = (int) ((long2-long1)/dx+1);
*n = (int) ((lat2-lat1)/dy+1);
*k = (int) ((depth2-depth1)/dh+1);
}
I used gcc to compile it: gcc -c GridDim.c
then I used the object file for a main file and compile that file
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int m,n,k;
GridDim(20.0,30.0,0.1,10.0,15.0,0.1,5.0,20.0,5.0,&m,&n,&k);
printf("m= %d\nn= %d\nk= %d\n", m, n, k);
return 1;
}
gcc test.c -o test GridDim.o
but I did not get the correct answer. Does anybody know why?
the answer should be m=101 n=51 k=4 but I got m=1 n=1 k=-12blahblah
No comments:
Post a Comment