need expert help

S

sipetar

I have two file.
file looks like this:

first file:

A#b1#c1
B#b2#c2
B#b3
C#b4#c4
D#b5#c5

second file:

B#q1
C#q2
C#q3
E#q4
F#q5

I need to write programm that simulates simple database and each table
is given by text file where each row represent one entry and fileds are
delimited with # mark.
first field is key of row and there can be more rows with same key.
So I need to write programm that will take those two file and print all
rows that have same keys( ).

I've got instructions : need to save row that matches
in the hash table(need to choose function that fits)
so that key of hash table is key of row and a value in hash table is a
pointer on the beginning of linked list
....if you understand what is the problem..

one of possible outputs:

B#b2#c2#q1
B#b3#q1
C#b4#c4#q2
C#b4#c4#q3

P.S I only dont undestrand how to write this part with hash table(newer
use it before) so if you can please explain me on example or if you can
write just this part with filling the hash table and reading the data
from hash table..
(If you are asking, yes this is my homework and I should write this on
my own, but it's easily for me to understand if I first read someone
else code...thanks)

I tried something:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(int argc, char *argv[]){

char *fn1, *fn2;
FILE *fstream1,*fstream2;

char* buff_d1, *buff_d2;

char search_s ='#';
int real_s;


if(argc!=3) exit(0);

fn1 = argv[1];
fn2 = argv[2];

if(!(fstream1 = fopen(fn1,"r")) || !(fstream2 = fopen(fn2,"r")))
exit(1);

search_s ='#';
buff_d1 = malloc(1);
buff_d2 = malloc(1);

real_s = 1;
while(!feof(fstream1)){

*buff_d1 = fgetc(fstream1);

if(!(buff_d1 = realloc(buff_d1,++real_s)))
exit(1);

}

real_s = 1;
while(!feof(fstream2)){

*buff_d2 = fgetc(fstream2);

if(!(buff_d2 = realloc(buff_d2,++real_s)))
exit(1);

}
//and now what?
// now I think that with "strtok(buff_d1,search_s)" put

free(buff_d1);
free(buff_d2);

return 0;
}
best regards
Sinisa
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top