Error in random function

Hello everyone,

i got an error in my code i tried many times to fixed it or change the syntax but i always get same error."error: expected a “)”.

this error comes becuse of random_ints function.

this is the code:

#include <assert.h>
#include <cuda.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <time.h>

#define N (1024*1024)
#define M (1000000)

void random_ints(int* a, int N)
   int i;
   for (i = 0; i < M; ++i)
    a[i] = rand() %5000;

__global__ void add(int *a, int *b, int *c) {
		c[blockIdx.x] = a[blockIdx.x] + b[blockIdx.x];

    int main(void) {
	int *a, *b, *c;		// host copies of a, b, c
	int *d_a, *d_b, *d_c;	// device copies of a, b, c
	int size = N * sizeof(int);
	// Alloc space for device copies of a, b, c
	cudaMalloc((void **)&d_a, size);
	cudaMalloc((void **)&d_b, size);
	cudaMalloc((void **)&d_c, size);

	// Alloc space for host copies of a, b, c and setup input values
	a = (int *)malloc(size); random_ints(a, N);
	b = (int *)malloc(size); random_ints(b, N);
	c = (int *)malloc(size);
        // Copy inputs to device
        cudaMemcpy(d_a, a, size, cudaMemcpyHostToDevice);
        cudaMemcpy(d_b, b, size, cudaMemcpyHostToDevice);

        // Launch add() kernel on GPU with N blocks
        add<<<N,1>>>(d_a, d_b, d_c);

        // Copy result back to host
        cudaMemcpy(c, d_c, size, cudaMemcpyDeviceToHost);

        // Cleanup
        free(a); free(b); free(c);
        cudaFree(d_a); cudaFree(d_b); cudaFree(d_c);
        return 0;

so if there any header required for this function or only the error in syntax?

this the solution i tryid and its work with me:

Consider how random_ints would be defined after the #define macros are interpreted:

void random_ints(int *a, int (1024*1024))
   int i;
   for (i = 0; i < 1000000; ++i)
    a[i] = rand() %5000;

Clearly, you cannot specify a numeric literal in a function’s declaration like this.

It seems as though the second parameter should be the array’s size. You can call it n to avoid colliding with N:

void random_ints(int *a, int n)
   int i;
   for (i = 0; i < n; ++i)
       a[i] = rand() %5000;

but i got another error:

Segmentation fault (core dumped)