need expert help

Discussion in 'C Programming' started by sipetar@inet.hr, Feb 23, 2005.

  1. Guest

    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
    , Feb 23, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shapper
    Replies:
    7
    Views:
    301
    shapper
    Feb 27, 2007
  2. Y2J
    Replies:
    5
    Views:
    322
    Victor Bazarov
    Aug 19, 2006
  3. Replies:
    10
    Views:
    610
    Jonathan N. Little
    Oct 20, 2007
  4. Replies:
    27
    Views:
    755
    Andy Dingley
    Oct 31, 2007
  5. Jack

    Still not resolved. Need expert help

    Jack, Mar 1, 2005, in forum: ASP General
    Replies:
    7
    Views:
    146
Loading...

Share This Page