[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 266 KB, 1024x787, strings.jpg [View same] [iqdb] [saucenao] [google]
4413288 No.4413288 [Reply] [Original]

Im implementing a word finder for finding words for scrabble, written in C. Yes, im writing it in C. Here is what im planning.

input from user will be the letters required by the board to fit, any blank spaces will be represented by asterisks, (*).

Im going to allow the program to build words longer than what is specified by the user, but not shorter (obviously). For example:

input: t*est

output:
test
tester
testes
....
etc.

Im referencing a .txt document with just over 300k words in it. If you search the internet, you can recreate it by visiting this website: http://people.sc.fsu.edu/~jburkardt/data/txt/dictionary.txt

My code is here, http://pastebin.com/WJ7piiWx

The problem im having is that its not alocating the correct amount of spaces. For some reason, its giving me strange output. See: http://pastebin.com/98DnrcXX

Looking for any help i can get. Please and ty in advance

>> No.4413316

>>4413288

Shameful self bump with 1 minor correction. In my post, i meant to say that the input would be t*st. The "e" i typed should have been replaced by the asterisk.

Im relatively new to the programming field, and im trying to keep my skills up between semesters by doing small projects like this, and others. Any help would be greatly appreciated. Ty.

>> No.4413344

One last bump from me and im off to bed. It would appear as though a decent number of people have viewed both the source code, and the output on pastebin. I'll keep this thread open in my browser and check back in the morning. Till them, goodnight.

>> No.4413369

C++fag here. I'm taking a look right now. I been drinkin' though so no guarantees I'll have anything useful to say.

>> No.4413370

also why aren't you just using regular expressions?

>> No.4413376

I looked. I'm surprised the code you've written gives the output your provide.

Given:
//Check to see if they're different, if so then return FALSE (0)
if(waldo[i] == word[i]){
return 0;

Note that the above does the opposite of what your comment suggests. Even then, the output doesn't make sense.

>> No.4413378

The code you posted doesn't do what you have in the example output.

If you want an asterisk to match any single character, you don't need lastCharPosition at all. Just match the string length, then each char or asterisk.

If you want an asterisk to match 1+ characters, and be able to support multiple asterisks, make a loop that advances two independent pointers, one per string. If waldo's pointer points at a normal char, test the corresponding char over in the word. If waldo's pointer points to an asterisk, advance word's pointer until it matches the character after waldo's asterisk. Stop if either pointer hits the end of their string. If both pointers hit the end, there is a match, otherwise there is no match. Bail out early if any non-asterisk mismatches.

>> No.4413387

Do you mean Hangman, not Scrabble?

This algorithm's worthless for Scrabble.

>> No.4413406

Okay, first things first, I'm reading your code and I see
>scanf("%s", waldo);
This is asking for errors, consider replacing with
fgets(waldo, MAX_LEN, stdin); /* The form of fgets is (what you're writing to, how many characters to read, where the input comes from) */

What this will do is prevent overflow errors in the case that the user enters more than MAX_LEN characters (you might like to try doing this with your program and observe what happens). For future implementation the sizeof command may be useful, and would be implemented like;

fgets(waldo, sizeof(waldo), stdin);

I'll have a look at the rest of your code and see if I can figure out what's going on later on.

>> No.4413430

Homework threads will be deleted, and the poster banned.

>> No.4413431

Why are you so afraid of pointers OP?

>> No.4414555

>>4413370

Not sure what you mean, im sure i should, but like i said, im pretty new. I've only had 1 formal class, and that was Intro to C. I'll admit, i was having a pretty hard time understand pointers towards the end too.

>>4413376
I see this, i was playing with that expression last night, right before i posted the code, it had been, and was supposed to be "!=". Its corrected now.

>>4413378
Im trying to get each asterisk to represent a single character that may be between "a" and "z". The fact that the word was scanned from a DICTIONARY should eliminate (within reason) the possibility of it not being allowed within scrabbles rules. Im also allowing it to match strings that are longer, the scrabble board continues beyond the last "forced" letter in most cases. (the user is responsible for matching after this point). Im not looking for a perfect program, just something that would quickly and correctly match words that would fit and give a user some hints/solutions.

>>4413387
k

>>4413406
I've heard scanf isnt the best when working with end users, im not planning on shipping this to a production enviornment, but i'll implement your change when i get back and see how it goes. Ty.

>>4413430
FYI: Im not in a programming class right now, thats why i took it upon myself to try and create this scrabble solver. Im not doing this for a grade, im doing this because i want to challenge myself and attempt to make it work. So, no this isnt homework.

>>4413431
Because i literally, know almost dick about them, and because of such, i dont even know where in my code i could use them to make it better. Im slowly learning.....

>> No.4414592

>>4413288
fun exercise, bro

Search for "The World's Fastest Scrabble Program" in an old ACM journal in your uni's library. It has some wicked data structures for fast dictionary searches, good for scrabble, anagrams, etc.

>> No.4416887

>>4414555

OP here, i have been looking into scrabble a little more. I just realized my program doesnt really work too well for the game. I guess i should have done a little more homework before trying to write the program. I'll start writing another program around the game rules of scrabble, and i'll post the results in a new thread soon.

As for now, does anyone why the hell my string matching program interprets a single asterisk "*" to mean any number of letters, instead of a singular wildcard? My code wasnt written that way, but thats clearly what its doing.

A strange side note, but this is my third re-write of this program. My first attempt used the built-in strcmp() function, however it only matched exact copies. My second attempt used a function written by Jack Handy. Google "jakk handy wildcmp c" and you should find it. That function did the EXACT same thing as the one that i wrote, but it didnt allow for words longer than the input to match.

It was after trying these 2 that i decided to write my own function, and after doing so, im scratching my head wondering what the fuck is going on. Im compiling in Windows 7 64, using Dev-Cpp 4.9.9.2 (gcc compiler w/ mingw). Ty once again for your help.