Skip to main content
GameDev.net gamedev.net
🔒 Locked

Coding question

Started by mk83 Apr 28, 2001 at 6:07 AM 0 replies 750+ views
Original Post
mk83
mk83
Hi Guys, I am writing a simple program at the moment to take input from a file and put it in an array. At the moment the code looks like this.
  
int fImport()
{
   char Box[4];
   SendMessage(hEBox,WM_GETTEXT,(WPARAM)4,(LPARAM)Box);
   iAmmTrans = 0;
   ifstream  Importfile("Import.txt");
   ofstream  Outputfile("Output.txt");

   char BUFFER[50];
   while (Importfile.getline(BUFFER,50,''\n''))
   {
      aTransports[++iAmmTrans].sTransType[0] = BUFFER[0];
      aTransports[iAmmTrans].sTransType[1] = BUFFER[1];
      aTransports[iAmmTrans].sTransType[2] = BUFFER[2];
      aTransports[iAmmTrans].sTransType[3] = BUFFER[3];
      aTransports[iAmmTrans].sTransType[4] = ''\0'';

      aTransports[iAmmTrans].sTransNum[0]  = BUFFER[4];
      aTransports[iAmmTrans].sTransNum[1]  = BUFFER[5];
      aTransports[iAmmTrans].sTransNum[2]  = BUFFER[6];
      aTransports[iAmmTrans].sTransNum[3]  = BUFFER[7];
      aTransports[iAmmTrans].sTransNum[4]  = BUFFER[8];
      aTransports[iAmmTrans].sTransNum[5]  = BUFFER[9];
      aTransports[iAmmTrans].sTransNum[6]  = ''\0'';

      aTransports[iAmmTrans].sBox[0]  = Box[0];
      aTransports[iAmmTrans].sBox[1]  = Box[1];
      aTransports[iAmmTrans].sBox[2]  = Box[2];
      aTransports[iAmmTrans].sBox[3]  = ''\0'';

      Outputfile <<  aTransports[iAmmTrans].sTransNum <<
      aTransports[iAmmTrans].sTransType << aTransports
      [iAmmTrans].sBox << endl;
   };
   return 0;
};
  
Which works, but is not very neat, plus the code to enter a string that is larger than 10 chars long would start to be a problem, I could not get, get or getline to work correctly, is there another way? should I be able to use get and getline to input into a array of char in a class ? Another problem I will be coming to soon is getting my program to kick off a .exe file on another computer, is there a way of doing that without writing a client for the other machine ? maybe a RFC ? Please try not to send full source code, I would just like a nudge in a general direction. Thanks, MK83
SHilbert
SHilbert
Well, actually, if you have a structure that''s laid out exactly like the file, you can do this:

FILEFORMATSTRUCTURE ffs;
ifstream ImportFile("Import.txt", ios::in | ios::binary);
ifstream.read((char*)ffs, sizeof(ffs));
ImportFile.close();

And that reads in the file in binary mode (or it should )

As for executing a program on one machine from another, there isn''t really a way to do that without writing a server or client for the other machine. If there was a built-in way to execute .EXE''s remotely, what would stop people from executing "format c:" on my comp?

Gaah!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.