my assignment is to take in a data file of all the possible letters for each die from the game Boggle. Here's a copy of the data file:
D R L X E I
C P O H S A
N H N L Z R
W T O O T A
I O S S E T
N W E G H E
B O O J A B
U I E N E S
P S A F K F
I U N H M Qu
Y R D V E L
V E H W H R
I O T M U C
T Y E L T R
S T I T Y D
A G A E E N
Each die takes 6 of the letters, and these are stored in a linked list. When I have tried to run the following code, I keep getting an error code: C:\Dev-Cpp\Makefile.win [Build Error] [Untitled1.o] Error -1073741819
I've tried using 3 different IDEs, but always seem to get some compiling issue. I can't seem to figure out where I'm going wrong! This isn't complete yet by any means but would rather figure this out before I keep going deeper and deeper. Thanks in advance!
code:
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define LENGTH 80
struct boggleDataNode{
char data[3];
struct boggleDataNode *nextData;
}*head;
struct boggleDieSideNode{
char dieSideData[3];
struct boggleDieSideNode *nextSide;
}*head1;
void readData(struct boggleDataNode temp);
int main(){
int counter = 0;
struct boggleDataNode *head;
struct boggleDieSideNode *head1;
struct boggleDataNode *temp;
*head = NULL;
*head1 = NULL;
*temp = *head;
readData(*temp);
system("pause");
return 0;
}
void readData(struct boggleDataNode temp){
//initializing variables including
//opening the input file
FILE *input = fopen("BoggleData.txt","r");
int name =0;
int id=0;
char data[96] ={};
//error checking that the file opened
if (input == NULL){
fprintf(stderr, "Can't open input file!\n");
exit(1);
}
while( fscanf(input, "%s", &data) != EOF)
printf("%s", data);
}
strongly suggest, when compiling to enable all warnings, then fix those warnings. Afterall, the compiler knows the language much better than us humans.
The following code
1) compiles cleanly,
2) has unneeded items either commented out or #if 0...#endif out
3) checks for input errors
4) uses 'perror()' to properly output system function error info including the message related to the current 'errno' value
5) closes the input file after all reading completed
6) the fscanf() will stop after reading one numeric char from the input file because %s will stop when any 'white space' is encountered.
try removing the ampersand from "&data" because i believe you're trying to read a string, so pass the string, not the direccion.
so you'd have this:
Whatever else in your program logic is wrong, there's also a syntax error in
since ISO C forbids empty array initializers. If your build breaks due to this, it may explain the "Build Error". If you want data to be zero initialized, a single
= { 0 }
will do.It is also a good idea to crank up the warning level of your compiler by adding appropriate options. What system (OS) is this? Which compiler?
In your code, change
to
as it seems you don't need a global pointer for that structure anyway. As per your usage, it will be shadowed by the local
head
.Same goes for
head1
also.Next, you assign
NULL
to a pointer itself, not to the variable it points to. (FWIW,NULL
itself is a pointer, an invalid one, though).Change
to