generalya_deo
asked on
database question
Hi
I am creating a simple database that opens, prints, views, deletes records from a file.
My question is how do you delete a certain record from the database?
The database is stored in a struct
so like
arr[i].name
arr[i].stuff.....
so lets say user wantst to delete record i=23...whats the process to do it? Thanks!
I am creating a simple database that opens, prints, views, deletes records from a file.
My question is how do you delete a certain record from the database?
The database is stored in a struct
so like
arr[i].name
arr[i].stuff.....
so lets say user wantst to delete record i=23...whats the process to do it? Thanks!
ASKER
and yet another question..ROFL....
when i'm adding records
lets say i'm adding record arr[i+1] where i is the last record in database...should i allocate memory for it before i do?
when i'm adding records
lets say i'm adding record arr[i+1] where i is the last record in database...should i allocate memory for it before i do?
ASKER
and yet another question..ROFL....
when i'm adding records
lets say i'm adding record arr[i+1] where i is the last record in database...should i allocate memory for it before i do?
when i'm adding records
lets say i'm adding record arr[i+1] where i is the last record in database...should i allocate memory for it before i do?
ASKER
printf("Enter Last:\n");
fgets(last, 10, stdin);
strcpy(arr[size+1].last,la st);
printf("Enter First:\n");
fgets(first, 20, stdin);
strcpy(arr[size+1].first,f irst);
printf("Enter Address:\n");
fgets(addr, 40, stdin);
strcpy(arr[size+1].addr,ad dr);
printf("Enter Age:\n");
scanf("%d",&arr[size+1].ag e);
scanf("%c", &c);
printf("Enter Id:\n");
scanf("%d",&arr[size+1].id );
scanf("%c", &c);
is this proper?
fgets(last, 10, stdin);
strcpy(arr[size+1].last,la
printf("Enter First:\n");
fgets(first, 20, stdin);
strcpy(arr[size+1].first,f
printf("Enter Address:\n");
fgets(addr, 40, stdin);
strcpy(arr[size+1].addr,ad
printf("Enter Age:\n");
scanf("%d",&arr[size+1].ag
scanf("%c", &c);
printf("Enter Id:\n");
scanf("%d",&arr[size+1].id
scanf("%c", &c);
is this proper?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
my_rec_t *stuipd;
stuipd=&arr[size+1];
scanf("%c", &c);
printf("Enter Last:\n");
fgets(last, 10, stdin);
strcpy(stuipd->last,last);
printf("Enter First:\n");
fgets(first, 20, stdin);
strcpy(stuipd->first,first );
printf("Enter Address:\n");
fgets(addr, 40, stdin);
strcpy(stuipd->addr,addr);
printf("Enter Age:\n");
scanf("%d",&stuipd->age);
scanf("%c", &c);
printf("Enter Id:\n");
scanf("%d",&stuipd->id);
scanf("%c", &c);
i'm trying to add a record...but all this is doing is overwritting records...what i'm i doing wrong?
size is just the number of records
stuipd=&arr[size+1];
scanf("%c", &c);
printf("Enter Last:\n");
fgets(last, 10, stdin);
strcpy(stuipd->last,last);
printf("Enter First:\n");
fgets(first, 20, stdin);
strcpy(stuipd->first,first
printf("Enter Address:\n");
fgets(addr, 40, stdin);
strcpy(stuipd->addr,addr);
printf("Enter Age:\n");
scanf("%d",&stuipd->age);
scanf("%c", &c);
printf("Enter Id:\n");
scanf("%d",&stuipd->id);
scanf("%c", &c);
i'm trying to add a record...but all this is doing is overwritting records...what i'm i doing wrong?
size is just the number of records
Are you incrementing your 'size' variable?
Should probably be:
stuipd=&arr[++size];
Or, if you want to store data in the zero-element of your array (arr[0]) and still have an accurate 'size':
stuipd=&arr[size++];
Should probably be:
stuipd=&arr[++size];
Or, if you want to store data in the zero-element of your array (arr[0]) and still have an accurate 'size':
stuipd=&arr[size++];
Nothing has happened on this question in more than 9 months. It's time for cleanup!
My recommendation, which I will post in the Cleanup topic area, is to
accept answer by gj62.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
jmcg
EE Cleanup Volunteer
My recommendation, which I will post in the Cleanup topic area, is to
accept answer by gj62.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
jmcg
EE Cleanup Volunteer
ASKER
when adding to the record
should i use fgets or scanf?....note some of the strucutres are char..and some of it are integers
and if fgets...can someone explain fgets...thx!