#include #include #include #include int main(int argc, char* argv[]) { char *FileData = NULL; struct stat statbuf; unsigned int fileSize = 0; unsigned int i; int hInfile = -1; int ret = -1; // read file hInfile = open("test.dat", O_RDONLY); // check to see if file exists before processing if (hInfile == -1) { return -1; } // get size of file fstat(hInfile, &statbuf); fileSize = statbuf.st_size; FileData = (char *) malloc(fileSize); ret = read(hInfile, (char *) FileData, fileSize); close(hInfile); for (i=0; i < ret; i++) printf("%c", FileData[i]); free(FileData); return 0; }