Originally Posted by
tabstop
Yes, but sizeof(temp) is not necessarily going to be the size of a long -- sizeof(long) is going to be the size of a long, and temp is not a long variable -- it's a pointer. (Now granted on many machines in current use these are the same size, but they don't have to be.) The typical idiom is to use sizeof(*temp) -- the size of the thing temp points to -- in your malloc and your read.
oh ic...that's right...that makes a lot more sense but it still doesn't work...i'm still having problems:
Code:
int main(int argc, char* argv[])
{
if(!InitCUDA()) {
return 0;
}
char* fileID;
long tempIntReader;
size_t bytes_read;
/* File Input Variables */
int lenFileName;
char *fileName;
FILE *whichFile;
char* buf;
buf = (char*)malloc(sizeof(char)*17);
//tempIntReader = (long*)malloc(sizeof(long));
/* # pixels and # bytes in a frame*/
int frm_size;
INT16_T *h_idata; /* input data on host */
float *h_odata; /* image data on host */
//frm_size = 512 x FFT_LENGTH; /* #pixels = image width x image length */
printf("Please enter the full file name (i.e. imagefile.raw)\n-> ");
scanf("%c", &fileName);
if((whichFile = fopen("1.RAW", "r"))== NULL) {
printf("Error while loading data from file %s.\n", fileName);
exit(0);
} else {
bytes_read = fread(buf, sizeof(buf), 17, whichFile);
for(int i = 0; i < 17; i++){
printf("%c", buf[i]);
}
memset(buf, '\0', sizeof(buf));
printf("\n");
bytes_read = fread(&tempIntReader, sizeof(long), 1, whichFile);
printf("%d", tempIntReader);
i tried that first, just reading in a long int and saving it to tempIntReader
then i tried:
Code:
long* tempIntReader;
tempIntReader = (long*)malloc(sizeof(long));
fread(tempIntReader, sizeof(long), 1, whichFile);
then i tried:
Code:
long* tempIntReader;
tempIntReader = (long*)malloc(sizeof(long));
fread(tempIntReader, sizeof(*tempIntReader), 1, whichFile);
i continously get this error:
Unhandled exception at 0x00403508 in CUDAWinApp4.exe: 0xC0000005: Access violation reading location 0xffffff31.
i'm more confused now than ever because I'm reading the right about of bytes, I now have the right size to save what was read in and I have the right type. What am I missing?
I tried resetting the iterator for the filePtr by:
fseek(whichFile, 17, SEEK_SET);
which sets the iterator at the exact spot of my long int