Link to home
Start Free TrialLog in
Avatar of generalya_deo
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!
Avatar of generalya_deo
generalya_deo

ASKER

also...another question lol
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!
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?
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?
     printf("Enter Last:\n");      
      fgets(last, 10, stdin);
      strcpy(arr[size+1].last,last);
      printf("Enter First:\n");
      fgets(first, 20, stdin);
      strcpy(arr[size+1].first,first);
      printf("Enter Address:\n");
      fgets(addr, 40, stdin);
      strcpy(arr[size+1].addr,addr);
      printf("Enter Age:\n");
        scanf("%d",&arr[size+1].age);
        scanf("%c", &c);
      printf("Enter Id:\n");
        scanf("%d",&arr[size+1].id);
        scanf("%c", &c);

is this proper?
ASKER CERTIFIED SOLUTION
Avatar of gj62
gj62

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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++];


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