Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

How to use c++ to create database

Status
Not open for further replies.

4980000

Computer
May 12, 2001
8
0
0
IN
Hi!
Can any one help me out to create a database using a c++ programs.I want to keep a record of all my employees,so in that case how to do it .
 
Replies continue below

Recommended for you

This depends on what version of C/C++ you are using. If you are using Microsoft Visual C++, you can go to the MSDN site to find out how to link to Excel, Access, etc.
If you are using C (not C++) you will want to use a linked list for your database. You create a structure whose members become the information you want to keep. Then declare pointers to the structure to allow you to traverse the list and keep the info in order. I don't have any code around for this type of database any more but you can find such a linked list in many places on the internet.
Try programmersheaven.com first since they have lots of code in nicely structured groups.

Good luck
Steve
 
hi steve
Thanks for your suggestions for my query.
steve you have suggested me to have a structured linked list to have a data base.
steve i have tryed out linked list with c & c++. But the
problem that i am facing is that when i create a linked list and add all my data it works fine .But the problem is that when i closed my linked list program and then again try to open the same programm and want to gather the information which i have added then i am unable to get it.
which means that the data remains till the programm is running.
so, there must be some solution for that.so if u could help in that case i would be very much helpfull for that.
bye steve
thanks once again.
 
Hello again! You will have to save your data in order to
retrieve it again. There are some neater file write/read methods available these days but no matter what compiler you are using, you can always fall back on the old (C) style of formatted i/o. These will work (as far as I can tell) with anything.
To begin with, you need to declare a pointer to a file. Files are structures in the old-style C syntax. This will look something like this:

FILE *fp; // Declare a pointer to a file structure
fp = fopen("junk.dat", "w+"); // This opens a file called
//junk.dat for writing (and reading).
//Now you want to write to the file - let's assume you have
//a data structure called Junk with three int members and a
//counter called cnt.
//Assuming that *p is a pointer to the structure.
while(i<=cnt)
{
fprintf(fp, &quot;%d\t&quot;,p->first);
fprintf(fp, &quot;%d\t&quot;,p->second);
fprintf(fp, &quot;%d\n&quot;,p->third);
i++;
}
//Now, close the file to observe the niceties
fclose(fp);

You can open the file again at any time and run thru a loop
looking for EOF. Same sort of thing as before:
fp = fopen(&quot;junk.dat&quot;, &quot;r+&quot;); //Open for reading +.
Use fscanf if you are sure your data will
always be properly formatted (by type). Otherwise you can use fgets and convert using atoi() or some such.
I hope this is of some help.

Steve
 
hi! Steve
Thanks again for your Suggestions!
Steve as u have said to use file handling to create a database i will do so.I have copied your code & with necessary changes i will try it out.
I will inform u about that.
thanks again

regards
feroz
 
HI steve..
came back to this forum after years...
saw ur replies..
nice to see someone replied to my queries..
well at this moment i have totally forgotten programming.. reason being not in touch,,

anyways..
byee
 
Status
Not open for further replies.
Back
Top