I've spent a few hours reading(and trying to understand) the FAQ, and I found this:
So I tried it in my call to fgets:Code:if (fgets(buf, sizeof(buf), stdin))
{
strtok(buf, "\n"); /* Remove the newline character */
walker(root, buf);
}
But I still can't open the files. I still get the same "invalid argument" messages. :)Code:while((fgets(LineData[counter1].storefilename, LINELENGTH, p_openfile) != NULL) && (counter1 < NUMBEROFFILES))
{
strtok(LineData[counter1].storefilename, "\n");
counter1++;
lastfilenumber1 = counter1;
}
EDIT: Ok, I'm doing a search of the forum, and it appears I need to use strchr etc to scan the string for the newline, and then remove it somehow. I will give that a go.
EDIT: Tried, this, but still doesn't work.
Maybe if I can find the length of the string, and put a \0 at (length-1). I'll try that.Code:while((fgets(LineData[counter1].storefilename, LINELENGTH, p_openfile) != NULL) && (counter1 < NUMBEROFFILES))
{
if((p_newline = strchr(LineData[counter1].storefilename, '\n')) != NULL)
*p_newline = '\0';
counter1++;
lastfilenumber1 = counter1;
}
EDIT: Ok, here's something that almost works.
Once I've used fgets to read the filenames into an array, I then use sscanf to read those names into another array
For some reason, sscanf doesn't read the newline, so when I use fopen on the second array, all the files open, except for the very last one. I'll can live with that for now. :DCode:for(counter1 = 0; counter1 < lastfilenumber1; counter1++)
{
sscanf(LineData[counter1].storefilename, "%s", &LineData[counter1].storefilename2);
}
EDIT:
Ok, finally got this to work:
MISSION ACCOMPLISHEDCode:if((p_newline = strchr(LineData[counter1].storefilename, '\n')) != NULL)
*p_newline = '\0';
C IS AWESOME! :D

