Thx Prelude.
"ok can u explain to me"linkedlist for dummies 2nd effort made"
samsam
"then again if linkedlist is good just for the life of the program.
then how does it attribute to a data base system."
then what confuses me is the fact that in all of the books
i have reviewed, its like linkedlists utilized , yet no effort is being
made into actually save it to a file or what.
if its made for a one time use.then where this data is being saved?what use ?
like this code that add banking info to the end of the list.
Code:
Name: BANK1.C
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <ctype.h>
#include <conio.h>
void addNewAccount(void);
struct account {
int number;
char lastname[15];
char firstname[15];
float balance;
struct account *next;
};
struct account *first,*current,*new;
int anum = 0;
void main()
{
char ch;
/* Initialize all the pointers */
first = (struct account *)NULL;
current = (struct account *)NULL;
new = (struct account *)NULL;
do
{
puts("\nA - Add a new account");
puts("Q - Quit this program\n");
printf("\tYour choice:");
ch = toupper(getch());
switch(ch)
{
case 'A':
puts("Add new account\n");
addNewAccount();
break;
case 'Q':
puts("Quit\n");
default:
break;
}
}
while(ch != 'Q');
}
void addNewAccount(void)
{
char buffer[64];
new = (struct account *)malloc(sizeof(struct account));
/* Check to see if this is the first record
* If so, then initialize all the pointers to this,
* first structure in the database
*/
if(first==(struct account *)NULL)
first = current = new;
/* Otherwise, you must find the end of the structure list
* (Easily spotted by the NULL pointer) and add on the
* new structure you just allocated memory for
*/
else
{
current = first; //make the first record the current one
//and loop through all records:
while(current->next != (struct account *)NULL)
current = current->next;
//the last record is found
current->next = new; //save the address of the new record
current = new; //and make the current record the new one
}
/* Now, you just fill in the new structure */
anum++;
printf(" Account number: %5i\n",anum);
current->number = anum;
printf(" Enter customer's last name: ");
gets(current->lastname);
printf("Enter customer's first name: ");
gets(current->firstname);
printf(" Enter account balance: $");
current->balance = atof(gets(buffer));
/* Finally, cap the new record with a NULL pointer
* so that you know it's the last record:
*/
current->next = (struct account *)NULL;
}
Ok we are adding more acc numbers to this banking database
but when the program ends everything is lost.
your answer may be:
ok then dumb samsam, we simply open a file . and read and
write into it .
which comes to my point that we still have to create that
file first and read and write into it.
i hate myself when im like lost.
cheers!