Hey guys,
I'm loading from a dictionary with a variable called "buffer". I'm trying to copy "buffer" in to another array word for word. For some reason, when I try using strncpy()
, it yields a segfault. Here is my code (assuming "LETTERS" is 29:
bool load(string filename)
{
// open dictionary
FILE* file = fopen(filename, "r");
if (file == NULL)
return false;
// load words from dictionary
char buffer[LETTERS + 2];
int size = 0;
while (fgets(buffer, LETTERS + 2, file))
{
// overwrite \n with \0
buffer[strlen(buffer) - 1] = '\0';
strncpy(arrayList[size], buffer, LETTERS + 2);
size++;
}
return true;
}
So I've tried printing the value of "buffer", and it prints just fine. I have no idea why this isn't working.