I have no need for a pearl script or anything since I just have a simple dictionary text file and want to be able to just load in the text file and do the same thing as it would do on that site but just on my computer like a basic c program.
However when I compile it, it gives a lot of errors such as "redeclaration of bg with no linkage" and undefined reference to 'dictionary' and 'n_words' ect.
How do I get this working on my computer? What modifications do I make?
I have no experience with make files and pearl scripts and such. Are a lot of modifications needed? Or do I just need to do things using basic file in/out in C?
You just need to make a file called "dict.c" from your words. Look at the Perl script from where it says <However when I compile it, it gives a lot of errors such as "redeclaration of bg with no linkage" and undefined reference to 'dictionary' and 'n_words' ect.
I don't know what operating system you are using, but there's a makefile at the bottom of the page which gives compilation instructions.
Yeah, Im trying to modify it so I can use a dictionary.txt file and run it in C without the make file or pearl script
As it stands the program is set to build using the dictionary compiled into a data segment. So you need to write some kind of parser for "dictionary.txt" to read it and put it into the appropriate data structure.
By the way, that is "makefile" and "Perl" not "make file" and "pearl".
You don't need the Pearl script at all. Do you have the dictionary file yet?
Forget the Pearl script, get the dictionary file, and take just copy the first 10 words of so, out, for a test file.
Now, what problems do you have?
The way that code is set up, that will not work. You need to write some parser to read the dictionary file in. The program is set up to put its data into the program itself.
So I can't just parse the dictionary.txt file into the dictionary array variable and pass that in?
extern const char * dictionary[];
I was thinking of using a file pointer and other stdio.h functions to read in the text file and put each word into an array index somehow. That way won't work?
So I can't just parse the dictionary.txt file into the dictionary array variable and pass that in?
extern const char * dictionary[];
I was thinking of using a file pointer and other stdio.h functions to read in the text file and put each word into an array index somehow. That way won't work?
I think you are stuck on more than just that program, you don't seem to know C very well. How about getting a copy of "The C programming language" by Kernighan and Ritchie and working through some examples. I don't think there is much else I can suggest.
Yeah I removed extern since extern was needed for the pearl script which I'm trying to do without. That was part of the original errors. But still trying to figure out how to get the wordlist into the array.
And yes, I do have the book "C programming A Modern Approach" which is a great book. However I like seeing how some programs work and I learn my tinkering around and doing stuff and I feel that doing what I want to do is simple and easy. I guess not.
Quick question do you know the relevance of the keyword extern ?
I removed extern and the program compiled with just 1 warning
The extern keyword means that the variable is defined outside of that source file. The warning you got probably came from using the variables that were declared as extern without defining any value for them.
I do not know how much you learn from just looking other's code, better do it on your own. I can say it as I did it myself in Python language: http://www.daniweb.com/software-development/python/code/299470 . you could try to use my approach in c and see how it compares with the ready program or my Python code.
Alright thanks, I don't know python at all but I'll take a look. It's actually a little difficult to (for me at least) to translate higher level languages down to C but your python might help me with the matrix traversal logic.
I've programmed java for about a year before C and stuff like str.charAt() and list.add() and other object oriented aspects, you have to make or find yourself on the web in C. I guess it's not that hard if you can make these functions but things we take for granted like arraylist in java and Vector in C++ you have to create on your own in C.
I'll spend a few more hours on this program over the next 2 days and see what I can do and I'll post back, but as of now I"m just still trying to figure out how to load and parse the dictionary.txt file. I'm still wondering if I just put it in the char dictionary[] array.
I compiled the file with the suggested installation process in windows under mingw, but the resulting compiled program produced wrong input it produced this output:
$ boggle
LOEV
UXNI
UIXQ
KPWB
XI
NO
NE
NI
NINE
NIX
NI
NIX
NINE
NIP
IE
IN
INO
IN
INO
XI
XI
PU
PI
PIX
PIN
PINO
PINE
PIK
PIP
WI
WIN
WINE
Nine is not possible as it folds back over itself, my newer version of program produce with same input:
Default language: US, dictionary: us.txt
Preparations: 127.661 ms
Give your boggle,
dimension number for random square,
two letter dictionary code
or q to quit:
loevuxniuixqkpwb
0: L O E V
4: U X N I
8: U I X Q
12: K P W B
95 candidates found in 1061.898 ms of which final check took 2.647 ms
Total 37 solutions.
NIXIE PIXIE ENOL EXON KINO LONE LUXE OXEN PINE PINO
VEIN VINE VINO WINE EON INO KIN KIP KUI LOU
LOX LUI LUO LUX NEI NEO NIP NIX NOU ONE
PIK PIN PIX VEI VEX VIE WIN
The linked browser version does not however produce NINE as result. Also minimum length of solutions should be 3: http://en.wikipedia.org/wiki/Boggle
I figure that I first need to figure out how to successfully load the entire text file of 30,000 or so words into the dictionary [] array. Using malloc or some define number perhaps. Then I need to figure out a way to terminate each word at each index with a '/0'. Or somehow make it dynamic so it terminates the end of a word using a strlength function (memory efficiency).
So eventually dictionary[] will contain the entire dictionary in memory which will make it easier for searching/other algorithms to use it in the program.
Notice: I am not the OP. I posted zipped the result of perl script: dict.c
Result of test case included in code (change #if 0 to #if 1) by my Python program with the dict.txt from this program as US dictionary gives as result:
FXIEAMLOEWBXASTU
0: F X I E
4: A M L O
8: E W B X
12: A S T U
199 candidates found in 1140.000 ms of which final check took 10.000 ms
Total 94 solutions.
EMBOLE FAMBLE SEMBLE WAMBLE AMBLE AWEST AXILE EMBOX LIMAX LIMBO LIMBU LIMES SWAMI AMBO AMIL AMLI ASEM AXIL AXLE BLEO BOIL BOLE EAST EMIL FAME LIMA LIMB LIME MESA MEWL MILE MILO OIME SAWT SEAM SEAX SEMI STUB SWAM TWAE TWAS WAME WASE WAST WEAM WEST AES AME AMI ASE AST AWA AWE AWL BLO BUT ELB ELI ELM FAE FAM IMA LEI LEO LIE LIM LOB LOX MAE MAW MAX MES MEW MIL MIX MWA OIL OLE OLM SAW SEA SEW STU SWA TUB TUX TWA WAE WAF WAS WAX WEA WEM WES
(sorted result first by length, then alphabet)
dict.txt has by the way 235882 words not, 30000.
I compiled program with above test case enabled with command also in Linux the code with edited Makefile
tony@tony-one:/media/Ysisoft_backup/MinGW/msys/1.0/home/Veijalainen/c$ make
cc -c -g -Wall boggle.c
./dict-to-inc.pl
cc -c -g -Wall dict.c
cc -o boggle -g -Wall boggle.o dict.o
tony@tony-one:/media/Ysisoft_backup/MinGW/msys/1.0/home/Veijalainen/c$ cat Makefile
cc=gcc
boggle: boggle.o dict.o
cc -o boggle -g -Wall boggle.o dict.o
boggle.o: boggle.c
cc -c -g -Wall boggle.c
dict.o: dict.c
cc -c -g -Wall dict.c
dict.c: dict.txt
./dict-to-inc.pl
tony@tony-one:/media/Ysisoft_backup/MinGW/msys/1.0/home/Veijalainen/c$ boggle
'boggle' ei ole tällä hetkellä asennettuna. Voit asentaa sen kirjoittamalla:
sudo apt-get install bsdgames
tony@tony-one:/media/Ysisoft_backup/MinGW/msys/1.0/home/Veijalainen/c$ ./boggle
FXIE
AMLO
EWBX
ASTU
MI
MA
ME
MWA
MWA
LI
LO
LOB
LOX
OE
OLE
OLM
OBOE
OBOL
OBOLE
OX
WA
WE
WA
BO
BOLE
BOB
BU
BUB
BUBO
BUT
SE
SWA
SWA
SA
ST
TWA
TWA
TU
TUB
TUX
TUT
TUTS
UT