Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Help with C Programming badly needed

  • 21-12-2011 11:44AM
    #1
    Registered Users, Registered Users 2 Posts: 2,250 ✭✭✭


    Hi all,

    I'm doing a programming course at the minute and am working on 2 programs. I really really need some help as I'm so stuck.

    If anyone could help me out I would really appreciate it.


Comments

  • Closed Accounts Posts: 20,759 ✭✭✭✭dlofnep


    It would help if you posted what the objectives are, what code you have written so far in attempt to achieve it, and where exactly you are stuck. Don't expect anyone to write a program from scratch for you.


  • Registered Users, Registered Users 2 Posts: 2,250 ✭✭✭adocholiday


    I'm writing a spellchecker at the minute. I have a dictionary file and a user text file. I have to compare the user file with the dictionary file and compare the 2. I'm thinking load the 2 files into memory and do a binary search. I have a function for loading the files, code below for one, but I'm completely lost with how to do a binary search. Is there an easier alternative?
    void readfile(char *dictionary) //Reads the dictionary file into memory for optimized searching//
    {
    FILE *fp1 = fopen("dictionary.txt","rb");
    
    fseek(fp1,0,SEEK_END);
    float endpos = ftell(fp1);
    
    fseek(fp1,0,SEEK_SET);
    
    char *dictionary = malloc(endpos);
    fread(dictionary, endpos, 1, fp1);
    
    fclose(fp1);
    }
    


  • Registered Users, Registered Users 2 Posts: 1,456 ✭✭✭FSL


    Get a piece of paper. Draw the logic for a binary search. Check it flows correctly with no dead ends. Then convert it into instructions which your computer can recognise.

    Irrespective of whatever language you are using the logic of a binary search remains the same.

    Working out the logic is programming, putting it into a form a computer
    recognises is coding.


Advertisement