Why am I getting “void value not ignored as it ought to be”?

  int a = srand(time(NULL));

The prototype for srand is void srand(unsigned int) (provided you included <stdlib.h>).
This means it returns nothing … but you’re using the value it returns (???) to assign, by initialization, to a.

Edit: this is what you need to do:

#include <stdlib.h> /* srand(), rand() */
#include <time.h>   /* time() */

#define ARRAY_SIZE 1024

void getdata(int arr[], int n)
    for (int i = 0; i < n; i++)
        arr[i] = rand();

int main(void)
    int arr[ARRAY_SIZE];
    getdata(arr, ARRAY_SIZE);
    /* ... */

Leave a Comment