B
BT
Ok, for a school assignment we have to use a pointer for an array of
ints, intstead of the usual X way, it compiles fine but when i run
it I am getting a seg fault that i can't figure out how to fix. It
occurs at this line:
*d = rand() % 99 + 1
Here is the code for the first part of the program, the line that
causes the seg fault is
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define MAXSIZE 11
int main()
{
int DATASIZE = MAXSIZE;
int *narray;
void getdata(int *d, int size);
int largest(int *d, int size);
getdata(narray, DATASIZE);
exit(0);
}
void getdata(int *d, int size)
{
int i;
srand(time(0));
for(i=0; i< size; i++) {
*d = rand() % 99 + 1;
d++;
}
}
Thanks in advance
ints, intstead of the usual X way, it compiles fine but when i run
it I am getting a seg fault that i can't figure out how to fix. It
occurs at this line:
*d = rand() % 99 + 1
Here is the code for the first part of the program, the line that
causes the seg fault is
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define MAXSIZE 11
int main()
{
int DATASIZE = MAXSIZE;
int *narray;
void getdata(int *d, int size);
int largest(int *d, int size);
getdata(narray, DATASIZE);
exit(0);
}
void getdata(int *d, int size)
{
int i;
srand(time(0));
for(i=0; i< size; i++) {
*d = rand() % 99 + 1;
d++;
}
}
Thanks in advance