From Genome Analysis Wiki
Jump to navigationJump to search
434 bytes added
, 17:26, 29 September 2010
Line 86: |
Line 86: |
| | | |
| | | |
− | ==== Example ====
| + | === Example === |
| <source lang="cpp"> | | <source lang="cpp"> |
| + | // specify to open stdin for read. |
| + | // replace the - with a filename in order to read from a file. |
| const char* filename = "-"; | | const char* filename = "-"; |
| IFILE myFilePtr = ifopen(filename, "rb", InputFile::BGZF); | | IFILE myFilePtr = ifopen(filename, "rb", InputFile::BGZF); |
| + | if (myFilePtr != NULL) |
| + | { |
| + | std::cerr << "Failed to open the file\n"; |
| + | } |
| + | else |
| + | { |
| + | // File was successfully opened. |
| + | // Read the magic string. |
| + | char magic[4]; |
| + | if(ifread(myFilePtr, magic, 4) != 4) |
| + | { |
| + | std::cerr << "Could not read 4 bytes from the file\n"; |
| + | } |
| + | ifclose(myFilePtr); |
| + | myFilePtr = NULL; |
| + | } |
| </source> | | </source> |