I'm having trouble using drand48 to feed an array, i tested the array using the loop counter and it stores that just fine.
When I use drand48 though, i get 7 0's in the first 7 spots, and the rest i get nan
Code:
/*
* Program to write an array to a file
* Array will be filled with random numbers using drand48 (0.0, 1.0)
*/
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main(int argc, char *argv[])
{
FILE *ofp;
int i, N;
double *A;
srand48((long)time(NULL));
if (argc != 2)
{
printf("Error with arguments, must have 2, program name and a integer for array");
exit(1);
}
N = atoi(argv[1]);
A = malloc((N + 1) * sizeof(double));
ofp = fopen("arrout.dat", "w");
fprintf(ofp, "Array size: %d\n", N);
for(i = 0; i < N; ++i)
{
A[i] = drand48();
fprintf(ofp, "%lf\n", A[i]);
}
return 0;
}