For my programming assignment this week I have a problem where I need to assign a value to a pointer in a subroutine and it doesn't seem to be reflected in the main part of the code.
now noOfFloatsMain is still zero, even though in readFloatDataAsDoublesFromFile() sets the value to 1896.
What am I doing wrong?
Code:
int main (int argc, const char * argv[]) {
/* read in data.*/
double *data;
//unsigned long v=0.0;/*So noOfFloatsP has something to initially point to.*/
unsigned long *noOfFloatsP;//=&v;
if(readFloatDataAsDoublesFromFile("prj4data.dat",data,noOfFloatsP)){
printf("Error reading in data, see previous error message for more details. Exitting the program.\n");
return 1;
}
if(noOfFloatsP==NULL){
printf("Error, pointer 'noOfFloatsP' is empty, exiting.\n");
exit(EXIT_FAILURE);
}
unsigned long noOfFloats=(unsigned long)*noOfFloatsP;
printf("noOfFloatsMain=%u\n",noOfFloats);
}
now noOfFloatsMain is still zero, even though in readFloatDataAsDoublesFromFile() sets the value to 1896.
What am I doing wrong?