/* * @(#)FileIOTest.C 0.1 1999/09/10 * * Copyright 1999 by Yoon Kyung Koo. * All rights reserved. * * This software is the confidential and proprietary information * of Yoon Kyung Koo. ("Confidential Information"). You * shall not disclose such Confidential Information and shall use * it only in accordance with the terms of the license agreement * you entered into with Yoon Kyung Koo. * */ /** * This program provides a test over * communication with java apps * * @version 0.1 1999/09/10 * @author Yoon Kyung Koo */ #include #include extern "C" { #include } typedef struct { char bytes[100]; char c; bool val; // usually bool type is defined as int, but it depends on O/S int str_length; // length of string char * string; // string bytes } Object ; void usage(const char * name) { cout << "\nUsage : " << name << " file1" << endl; } int main(int argc, char ** argv) { if (argc < 2) { usage(argv[0]); exit(1); } Object object; cout << "address of object : " << hex << &object << endl; cout << "offset to bytes : " << dec << (int)&object.bytes - (int)&object << endl; cout << "offset to c : " << dec << (int)&object.c - (int)&object << endl; cout << "offset to val : " << dec << (int)&object.val - (int)&object << endl; cout << "offset to str_l : " << dec << (int)&object.str_length - (int)&object << endl; cout << "offset to string : " << dec << (int)&object.string - (int)&object << endl; cout << "whole size of the Object class : " << dec << sizeof(Object) << endl; ifstream fs(argv[1]); if (fs.bad()) { cerr << "cannot open " << argv[1] << endl; exit(1); } // size of whole object - size of Object::string int len = sizeof(Object) - sizeof (char *); fs.read((char *)&object, len); if (fs.bad()) { cerr << "stream errored." << endl; exit(1); } // always fix byte order object.val = ntohl(object.val); object.str_length = ntohl(object.str_length); len = object.str_length; object.string = new char[object.str_length + 1]; fs.read(object.string, len); if (fs.bad()) { cerr << "stream errored." << endl; exit(1); } object.string[object.str_length] = 0; // append null cout << "bytes :" << endl; for (int i=0; i<100; i++) { if (i%10 == 0) cout << endl; cout << dec << (int) object.bytes[i] << " "; } cout << endl; cout << "c : " << object.c << endl; cout << "val : " << (object.val?"true":"false") << endl; // cout << "len : " << object.str_length << endl; cout << "string : " << object.string << endl; }