Visit the Ironworks Gaming Website Email the Webmaster Graphics Library Rules and Regulations Help Support Ironworks Forum with a Donation to Keep us Online - We rely totally on Donations from members Donation goal Meter

Ironworks Gaming Radio

Ironworks Gaming Forum

Go Back   Ironworks Gaming Forum > Ironworks Gaming Forums > General Discussion > General Conversation Archives (11/2000 - 01/2005)

 
 
Thread Tools Search this Thread
Old 02-02-2003, 09:12 PM   #1
Blade
Emerald Dragon
 

Join Date: March 12, 2001
Location: spokane wa usa
Age: 40
Posts: 926
ok so i spaced over break [img]tongue.gif[/img] i can't seem to figure out/rember how to read a file into a struct. I have written the struck and opened the files and checked them. Can anyone point me in the right direction? All i need to do is put the info in the file into different parts of the struct. Goes off muttering about homework.
__________________
<br /><br />All blades cut, be they made from metal or wood, but the sharpest and deadliest blade is the one of knowledge, and that is the least used.<br />An Archmage of the HADB
Blade is offline  
Old 02-03-2003, 02:52 AM   #2
Blade
Emerald Dragon
 

Join Date: March 12, 2001
Location: spokane wa usa
Age: 40
Posts: 926
lol i think i scared people away good thing i didn't post my calc. or physcics
__________________
<br /><br />All blades cut, be they made from metal or wood, but the sharpest and deadliest blade is the one of knowledge, and that is the least used.<br />An Archmage of the HADB
Blade is offline  
Old 02-03-2003, 07:42 AM   #3
andrewas
Harper
 

Join Date: October 2, 2001
Location: Aberdeen, Scotland
Age: 42
Posts: 4,774
(variable) &lt&lt (file)?

Or does the file handle class have a read method? Ive never used files much in C++.

Neatest way to do it would be to overload the &lt&lt operator for your struct (which dosent neccesaerily mean turn it to a class, structs can have methods to) and just use the one call. But as long as it works youll get marks for it.
andrewas is offline  
Old 02-03-2003, 09:11 AM   #4
Vaskez
Takhisis Follower
 

Join Date: April 30, 2001
Location: szép Magyarország (well not right now)
Posts: 5,089
Why don't you just set up file objects....the following example is from my old BG2 XP Patcher:

FILE *f = fopen("BGMain.exe","rb+wb");
FILE *f2 = fopen("VKXPPatcher.log","rb+wb");
fread(&d,8,1,f2);

location = (int)d;
fsetpos(f,&location);
fread(&e,4,1,f);

as you can see I open 2 files for binary read and binary write and then read into the address of the variable "d" 8 bits from the file f2. You can set the read position with fsetpos....those are C methods though, which would of course work in C++ but I guess you have to do it with C++ methods?
__________________
Too set in his ways to ever relate
If he could set that aside, there'd be heaven to pay
But weathered and aged, time swept him to grave
Love conquers all? Damn, I'd say that area's gray
Vaskez is offline  
Old 02-03-2003, 09:41 AM   #5
andrewas
Harper
 

Join Date: October 2, 2001
Location: Aberdeen, Scotland
Age: 42
Posts: 4,774
My previous post is embarassingly wrong. Use:

(file) &gt&gt (variable); instead.

I need more C++ practice.

What you get depends on what (variable) is. If its a BYTE you get one byte of data and have to write your own parser. Most versatile way of doing it, but hardly elegant.
__________________
[img]\"http://www.sighost.us/members/Zvijer/andrewas.gif\" alt=\" - \" />
andrewas is offline  
Old 02-05-2003, 02:36 AM   #6
Blade
Emerald Dragon
 

Join Date: March 12, 2001
Location: spokane wa usa
Age: 40
Posts: 926
well thanks for the replies, would have replyed earlier but the homework piles up quickly In case you were wondering what the code looks like, hay no snickering so what i'm proud of my work [img]tongue.gif[/img] here it is.
code:
//This Program was written by Chris Nance
//The class is CS 113
//The date last modified 2 Febuary 2003

//This program reads in from one file the name and ip address of one set of computers
//and then matches them with another ip address read in from a second file, if the ip address
//doesn't match then it says so

#include <iostream>
#include <cstring>
#include <fstream>
using namespace std;

struct NamesWithId
{
char name[20];
int address1, address2, address3, address4;
};

struct CheckId
{
int address1, address2, address3, address4;
};

void checkip(NamesWithId FirstFile[], CheckId checker[]);

void main()
{
char list[30], query[30],ch;
NamesWithId FirstFile[150];
CheckId checker[20];
ifstream check, input;
int i, x;

cout << "Enter the name of the .list file" << endl;
cin >> list;

cout << "Enter the name of the .query file" << endl;
cin >> query;

input.open (list);
if ( input.fail() )
{
cout << "error opening .list file\n";
exit(0);
}
check.open (query);
if ( check.fail() )
{
cout << "Error reading .query file\n";
exit(0);
}

while(!input.eof())
{
for ( i = 0; i < 150; i++)
{
input >> FirstFile[i].name;
input >> ch;
input >> FirstFile[i].address1;
input >> ch;
input >> FirstFile[i].address2;
input >> ch;
input >> FirstFile[i].address3;
input >> ch;
input >> FirstFile[i].address4;
}
}
while(!check.eof())
{
for ( x = 0; x < 20; x++)
{
check >> checker[x].address1;
check >> ch;
check >> checker[x].address2;
check >> ch;
check >> checker[x].address3;
check >> ch;
check >> checker[x].address4;
}
}

checkip(FirstFile, checker);

}


//This file compares the two arrays of structs
void checkip(NamesWithId FirstFile[],CheckId checker[])
{
int i, x, output;
for (x = 0; x < 20; x++)
{
for (i=0; i<150; i++)
{
if( FirstFile[i].address1 == checker[x].address1)
{
if( FirstFile[i].address2 == checker[x].address2)
{
if( FirstFile[i].address3 == checker[x].address3)
{
if( FirstFile[i].address4 == checker[x].address4)
{
output = 1;
}
else output = 0;
}

}

}
if (output == 1)
{
cout << "The computer name is: " << FirstFile[i].name << " The ip address is: "
<< FirstFile[i].address1 << "." << FirstFile[i].address2 << "." << FirstFile[i].address3
<< "." << FirstFile[i].address4 << endl;
output = 0;
break;
}

}
}
}
[/QUOTE]probably not elegant and it outputs a couple misalanious lines, and doesn't tell you if the input file is over 150 lines long but it works in the parameters, well except for telling you if the input is over 150 lines i was being lazy and thinking whail having a headach isn't the most conductive thing for programing. Just give me credit if you "borrow" the code or parts of it the input from the file to the struct was monumentally eazy once i rembered how to do it *shakes head in shame* o well. All you do is say input >> variable. where input is the input file stream and variable is what you want to put it into. Told you i wasn't thinking, you were right thanks. For the rest of the odd syntax problems i have i'm thankfull visualstudio.net

[ 02-05-2003, 02:38 AM: Message edited by: Blade ]
__________________
<br /><br />All blades cut, be they made from metal or wood, but the sharpest and deadliest blade is the one of knowledge, and that is the least used.<br />An Archmage of the HADB
Blade is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
a small question in regards to compression and files Harkoliar General Conversation Archives (11/2000 - 01/2005) 10 11-26-2003 12:16 AM
Need help with some MP3 files Xen General Conversation Archives (11/2000 - 01/2005) 8 09-13-2003 05:51 AM
IW should be on X-files. Neb General Conversation Archives (11/2000 - 01/2005) 25 09-18-2001 04:47 PM
EFF Files Azred Baldurs Gate II Archives 0 06-10-2001 10:04 AM
Help converting wac.files into wav.files? t1d Baldurs Gate II Archives 6 05-23-2001 03:04 PM


All times are GMT -4. The time now is 12:42 AM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
©2024 Ironworks Gaming & ©2024 The Great Escape Studios TM - All Rights Reserved