Word Search Using C

This is a discussion on Word Search Using C within the C Programming forums, part of the General Programming Boards category; Hi guys, first of all, this isn't an assignment or anything. I know people here are irritable when it comes ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    37

    Word Search Using C

    Hi guys, first of all, this isn't an assignment or anything. I know people here are irritable when it comes to help with assignments. This is just something I want to try out for sharpening my skills.

    I wanted to know if it is possible to do a word search with C when my knowledge is limited to arrays, multidimensional arrays, strings, arrays of strings and dynamic memory allocation (dynamic multidimensional arrays).

    The program I had in mind is, the main function would create an array of strings, and then it would call a search function. The search function would search vertically, horizontally and diagonally through the supplied array and see if a specific word is found.

    If someone has some ideas on how to do this, could you give me a general idea on how to get started? I'm having writers block here. Thanks

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    It is certainly possible to do something like that.

    I think a great place to start is this:

    Code:
    #include <stdio.h>
    
    int main(void){
      return 0;
    }
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    Registered User Char*Pntr's Avatar
    Join Date
    Sep 2007
    Location
    Lathrop, CA
    Posts
    198
    Quote Originally Posted by CProgramming11 View Post
    Hi guys, first of all, this isn't an assignment or anything. I know people here are irritable when it comes to help with assignments. This is just something I want to try out for sharpening my skills.

    I wanted to know if it is possible to do a word search with C when my knowledge is limited to arrays, multidimensional arrays, strings, arrays of strings and dynamic memory allocation (dynamic multidimensional arrays).

    The program I had in mind is, the main function would create an array of strings, and then it would call a search function. The search function would search vertically, horizontally and diagonally through the supplied array and see if a specific word is found.

    If someone has some ideas on how to do this, could you give me a general idea on how to get started? I'm having writers block here. Thanks
    I'm having "answering blocks here". At least give it try, convert your problem to
    pseudo code would be a start.

    Pseudo code Examples

  4. #4
    Registered User
    Join Date
    Oct 2010
    Posts
    37
    I know its possible. I'm asking if it's feasible with the limited programming abilities I have.

    If you don't want to give any serious input or contribute in any way, why even waste your time replying?

  5. #5
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    I think you should worry less about what's feasible and what's not and get your hands dirty working with all sorts of code. That is the best way to get better. Read and write a lot of code. There is no miraculous substitute for that.

    So if you have an idea for a program that involved string manipulation attempt it with your limited knowledge. It's not going to be something you can sell for sure, but it's going to help you learn something along the way. You can certainly have a go at it with your current knowledge.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  6. #6
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    You can even turn it into a sort of primitive scrabble game.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by CProgramming11 View Post
    I know its possible. I'm asking if it's feasible with the limited programming abilities I have.
    How do you think a programmer learns... by doing!

    The more you do the more you expand your programming abilities... Stretch yourself, give it your best shot. Take note of how much you learn trying to figure it out.

    If you don't want to give any serious input or contribute in any way, why even waste your time replying?
    Believe me you are getting the best help possible, right here, from these guys.
    The message is ... go for it! Give it your best shot.

    If you get stuck, post what you've got and maybe we can help you debug it...

  8. #8
    Registered User Char*Pntr's Avatar
    Join Date
    Sep 2007
    Location
    Lathrop, CA
    Posts
    198
    I'm sorry, my reply was not clear to you. I provided a link for you to click on. You stated your objectives clearly, so I think your next step should be to convert that to pseudo code.

    Click here ----> Pseudocode Examples

    But we're not here to do your homework. You have to show some effort in this.

  9. #9
    Registered User
    Join Date
    Oct 2010
    Posts
    37
    As I originally said, this is NOT homework. Could have saved yourself a line of text there.

    Also, I wasn't replying to you, I was replying to the first, sarcastic poster.

    I was in the process of writing it in pseudo code but couldn't wrap my head around it, so I was trying to see if I could get a nudge in the right direction.

  10. #10
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Quote Originally Posted by CProgramming11 View Post
    As I originally said, this is NOT homework. Could have saved yourself a line of text there.

    Also, I wasn't replying to you, I was replying to the first, sarcastic poster.

    I was in the process of writing it in pseudo code but couldn't wrap my head around it, so I was trying to see if I could get a nudge in the right direction.
    It is exactly this attitude of "oh I know it all already, but just wanted to check with you guys" that will continue getting you sarcastic remarks.

    My advice is, drop the attitude, everyone who is posting here is trying to help you and if you are not open to advice, criticism and a little fun you are in the wrong place. I was not making fun of you, I was just gently hinting at the fact that you have hardly provided anything that you need help with. We don't know where you want to start because we don't know what you want to do exactly. There are a million ways to go about this and it's better for you to figure out which path you will take. Then, we can guide you along it.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  11. #11
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    If you are reading from a file, the basic steps you could take.

    * read one line at a time from file

    * tokenize the line (ie replace space with '\0')

    * compare each substring in the line with your array of words

    * for each match, increment that word in a distribution array, (same index as your array of words)

    * present the results.

    I would create a tokenize() and search() function, (alternatively you could use strtok() instead). If you're not reading from a file but plan to compare two array of strings, you wont need to separate into substrings of course.
    Last edited by Subsonics; 11-07-2010 at 02:50 PM.

  12. #12
    Registered User
    Join Date
    Oct 2010
    Posts
    37
    First, thanks subsonics

    To Cladiu: I never said I knew it already. I actually said I did not know it, even to the point of not even knowing if it was possible with my methods or even how to write the pseudo code, so I'm not sure where you're picking up on that attitude. The post you just wrote was much more helpful than the 'int main (void)' post you originally wrote, so why even bother with the first post?

  13. #13
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Quote Originally Posted by CProgramming11 View Post
    First, thanks subsonics

    To Cladiu: I never said I knew it already. I actually said I did not know it, even to the point of not even knowing if it was possible with my methods or even how to write the pseudo code, so I'm not sure where you're picking up on that attitude. The post you just wrote was much more helpful than the 'int main (void)' post you originally wrote, so why even bother with the first post?
    I think we started off on the wrong foot and I am sorry about that. I wasn't being sarcastic, I was just joking which is why I included a smiley at the end of my post so it didn't sound like I was making fun of you. The int main joke is pretty standard answer to people that say they don't know where to start. It's nothing personal

    Now, in terms of your project, from what I understand you want to read in a 2D array of characters and then perform a complex search on it. So why not start with just reading that array in and making sure you have it stored properly in your array.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  14. #14
    Registered User
    Join Date
    Oct 2009
    Posts
    17
    Is there a possibility that this thread can be merged with the getChar thread? If not, is it alright if we continue talking about your issues in this thread CProgramming11? I'm getting confused jumping between the threads.

    In your getchar thread, it seems like you are on the right track.

  15. #15
    Registered User
    Join Date
    Oct 2010
    Posts
    37
    The getchar problem is resolved thanks to you.

    If anyone wants to further help on the wordsearch problem, that would be fine with me.

    Claudiu we definitely started off on the wrong foot. It's probably a little of my fault, I should have posted some of my (failed) ideas to show you guys what I was getting at. Anyway it's a work in progress that I don't even need an answer to really. If anyone wants to help the cause I am still interested in further ideas however.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 10-14-2010, 10:35 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  3. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  4. finding strings in strings
    By watshamacalit in forum C Programming
    Replies: 14
    Last Post: 01-11-2003, 01:08 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21