I have a couple questions I couldn't find solutions for. Not sure if I'm just not searching for the right terms...

I'm reading in lines from a text file using fgets() and sending the output to a list box. Unfortunately, since fgets() also reads in the null terminator, this is displayed in the list box as a pipe (|) at the end of the string in the list box display. (At least I'm assuming this is the cause.)

I am wondering how this can be avoided. I've tried a few different methods, including writing the char array to a new one and terminating when it gets to the null char, but for some reason this wouldn't work either.

As an aside, my main problem with this null terminator arises when I remove items from the list box and I have the program read each value remaining in the list box after the removal and truncate the file to re-write only the remaining values. But if you removed a value with a null terminator showing in the list box, there is a blank line inserted in the re-written file at this position.


My code to read from file to list box is:

Code:
FILE *inp;
inp = fopen("file.txt", "r");

if (inp != NULL)
{
	char FileInput[1001] = {'\0'};

	while(fgets(FileInput, 1000, inp)!=NULL)
	{
		SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)FileInput);
	}

	fclose(inp);
}

And the code to re-write the file after removal of selected items:

Code:
// Get number of items remaining in list box
count = SendMessage(hList, LB_GETCOUNT, 0, 0);

// Initialize index array
index = GlobalAlloc(GPTR, sizeof(int) * count);

// Write remaining items to truncated file
FileData = (char *)malloc(sizeof(char) * 1001);

// Find the index value, buffer data at the index, and write it to file
for(i = 0; i < count; i++)
{
	index = (long *)SendMessage(hList, LB_GETITEMDATA, (WPARAM)i, 0);
	SendMessage(hList, LB_GETTEXT, (WPARAM)(index+i), (LPARAM)FileData);
	fprintf(mod, "%s\n", FileData);
}