GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 05-Dec-2007, 10:47
Pramann Pramann is offline
New Member
 
Join Date: Nov 2007
Posts: 21
Pramann is on a distinguished road

Check a DAT file for data


I'm using C++, Visual Net
and I'm trying to use a DAT file to save vectors
The program i am writing is like a database were you can enter, view, and change the data inside the DAT file.
the vector i'm using is:
CPP / C++ / C Code:
struct Birthday
	{ 
		string Name;
		int Month;
		int Day;
		int Year;
	};

vector<Birthday> Birthdays;

what do i code so that if the file has no data it will just continue on?
  #2  
Old 05-Dec-2007, 11:11
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 466
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Check a DAT file for data


How about a function like:

CPP / C++ / C Code:
void LoadFromFile( string FileName, vector<Birthday>& Birthdays )
{ if( file does not exist ) return;

  // Assuming each Birthday is on a single line with Name,Month,Day,Year separated by a delimiter (like a comma)
  
  // for each line, create a Birthday struct (Birthday), populate it, and add it to Birthdays via Birthdays.push_back( Birthday );
}

CPP / C++ / C Code:
//call it like this:
vector<Birthday> Birthdays;
LoadFromFile("C:\\Birthdays.dat",Birthdays);
  #3  
Old 06-Dec-2007, 10:36
Pramann Pramann is offline
New Member
 
Join Date: Nov 2007
Posts: 21
Pramann is on a distinguished road

Re: Check a DAT file for data


Okay so my protocol is
CPP / C++ / C Code:
int check = 1;
int LoadFromFile("C:\\Birthdays.DAT",vector<Birthday> Birthdays, int check);

and then i call it up like
CPP / C++ / C Code:
LoadFromFile("C:\\Birthdays.DAT",Birthdays, check);
if(check == 1)
{
	List(Birthdays);
}
List being another function of mine that prints out the Birthdays

the function LoadFromFile contains
CPP / C++ / C Code:
int LoadFromFile("C:\\Birthdays.dat", vector<Birthday>& Birthdays, check )
{ 
	if( file does not exist )
	{
		check = 0;
	}
	return check;
}

why doesn't it work still?
  #4  
Old 06-Dec-2007, 11:53
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 466
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Check a DAT file for data


A couple of things...

1) your function definition for Load(....) does not match the implementation character-by-character.

2) file does not exist is not a value/function/anything. You have to reference a function that already exists. I'm not sure what that might be but check for something like bool FileExists( char* filename ).
  #5  
Old 06-Dec-2007, 17:29
Pramann Pramann is offline
New Member
 
Join Date: Nov 2007
Posts: 21
Pramann is on a distinguished road

Re: Check a DAT file for data


thanks
i fixed it
i used cin.peek() to see if the file has anything in it
 
 

Recent GIDBlogMeeting the local Iraqis by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 07:44
Read a .html file, check that file for links salemite C Programming Language 10 17-Jan-2008 07:56
Download files in c for windows operating system oozsakarya C Programming Language 5 20-Jun-2006 03:33
CD burner wont burn!! robertli55 Computer Hardware Forum 1 18-Jun-2004 10:53
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 11:28

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:48.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.