Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Help with C Programming badly needed

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


    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,016 ✭✭✭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