000
25.02.2007, 19:47 Uhr
~shed
Gast
|
Hallo!
Habe versucht ein jp2 file einzulesen. Funktioniert aber leider nicht. Mit fseek und ftell woltle ich die filegröße herausbekommen. Liefert mir aber immer 0. Weiß vielleicht jemand was ich falsch mache? Danke
C++: |
FILE* fp2 = fopen("city.jp2" , "rb"); if(fp2 != NULL) { char* buffer; int i =100; size_t result;
// obtain file size: fseek (fp2 , 0 , SEEK_END); int lSize = ftell(fp2); fseek (fp2 , 0 , SEEK_SET);
std::cout << lSize << "\n"; // allocate memory to contain the whole file: buffer = (char*) malloc (sizeof(char)*lSize); if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);} // copy the file into the buffer: result = fread (buffer,1,lSize,fp2); std::cout << result << "\n"; if (result != lSize) {fputs ("Reading error",stderr); exit (3);} /* the whole file is now loaded in the memory buffer. */ std::cout << buffer << " Länge:" << strlen(buffer); std::cout << "\n"; // terminate fclose (fp2); free (buffer); }
|
mfg, shed |