Dear,
I am fairly new to programming on the TMS. I am trying to read data from a .pcm file using the fopen and freads. The code is this:
int main( void ) { int v,e,tmp1; //int index=0 ; FILE *fpv; FILE *fpo; char tempc[2]; int U[2]={0,0}; int A[1]={16384}; int rho[2]={29491, 29491}; //rho=0.9, rho^2 printf( "\n***Program has Started***\n" ); fpv = fopen("..\\data\\in.pcm", "rb"); printf( "reading file opening\n" ); fpo = fopen("..\\data\\out.pcm", "wb"); printf( "writing file opening\n" ); if (fpv == NULL){ printf("Can't open input file\n"); return 0; } if (fpo == NULL){ printf("Can't open output file\n"); return 0; } fseek(fpv, 0, SEEK_SET); tmp1 = fread(tempc, sizeof(char), 2, fpv); if(ferror(fpv)){ //printf ("Error Reading from in.pcm\n"); perror("Error"); } printf("amount of data read %d\n", tmp1); printf("first data is %d\n", tempc[0]); /* * tempc = pointer to a block of memory with a minimum size of sizeof(char)*2 bytes. * each element read is one byte sizeof(char). 2 elements are read out at a time * (hence tempc[2], this is in total one data object that is read consisting of 2 * elements each a char wide) * fread returns the total amount of elements read to tmp1 (which should be 2) */ //Begin filtering the data fclose(fpv); fclose(fpo); printf( "\n***Program has Terminated***\n" ); }
I can "open" the files (which are in a map in the project on CCS), and no errors occur. But, whenever doing fread, it returns 0. Even though, there is data in the file (about 32kB). Any ideas why?