int main(int argc, char **argv) { OpenFileID fd; char filename[256]; char userinp[256]; char buffer[256]; int bytes_read; int i; PrintString("Nhap ten file can dump: "); ReadFile(filename, 256, 0); fd = OpenFileFunc(filename, 1); if (fd == -1) { PrintString("Khong the mo file.\n"); return 1; } do { bytes_read = ReadFile(buffer, 255, fd); if (bytes_read <= 0) break; for (i = 0; i < bytes_read; i++) { print_hex(buffer[i] / 16); print_hex(buffer[i] % 16); PrintString(" "); if (i % 16 == 15) PrintString("\n"); } } while (1); PrintString("\n"); return 0; }
int main(int argc, char* argv[]) { char mess[255]; unsigned int i ; OpenFileID inConsole = OpenFileFunc("stdin", 2); OpenFileID outConsole = OpenFileFunc("stdout", 3); if (inConsole == -1 || outConsole == -1) { PrintString("Can not open console\n"); return 0; } ReadFile(mess, 255, inConsole); WriteFile(mess, 255, outConsole); CloseFile(inConsole); CloseFile(outConsole); return 0; }
int main(int argc, char* argv[]) { char c; OpenFileID srcId; OpenFileID dstId; char source[255], dest[255]; int srcSz, srcPos; PrintString("Input source file:"); ReadString(source, 255); PrintString("Input destination file:"); ReadString(dest, 255); PrintString(source); srcId = OpenFileFunc(source, 1); CreateFile(dest); dstId = OpenFileFunc(dest, 0); if (srcId == -1 || dstId == -1) { int errorId = srcId == 0 ? 1 : 2; PrintString("Can not open file \n"); PrintString("Terminate program\n"); return 0; } /* Seek source file to end of file */ srcSz = SeekFile(-1, srcId); /* Seek destination file to begin of file */ SeekFile(0, dstId); while (srcSz>=0) { SeekFile(srcSz, srcId); ReadFile(&c, 1, srcId); WriteFile(&c, 1, dstId); PrintString("Test = "); PrintChar(c); PrintChar('\n'); srcSz --; } CloseFile(srcId); CloseFile(dstId); return 0; }
int main(int argc, char* argv[]) { OpenFileID srcId; OpenFileID dstId; char source[255], dest[255]; int filesz,srcsz, i; char c; PrintString("Input source file:"); ReadString(source, 255); PrintString("Input destination file:"); ReadString(dest, 255); PrintString(source); srcId = OpenFileFunc(source, 1); CreateFile(dest); dstId = OpenFileFunc(dest, 0); if (srcId == -1 || dstId == -1) { int errorId = srcId == 0 ? 1 : 2; PrintString("Can not open file \n"); PrintString("Terminate program\n"); return 0; } filesz = SeekFile(-1, srcId); SeekFile(0, srcId); SeekFile(0, dstId); for (i = 0; i < filesz; ++i) { ReadFile(&c, 1, srcId); WriteFile(&c, 1, dstId); } CloseFile(srcId); CloseFile(dstId); return 0; }