I tried to scan a text file ( contains decimal numbers) and save all the numbers into 1 array input1[50]. When I ran the code, the printout is always 1.0000 eventhough my text file have a bunch of numbers.
Could somebody point out where I did wrong? Thank you.

VOID CALLBACK TimerSend1(HWND hWnd,	UINT uMsg,	UINT_PTR idEvent,	DWORD dwTime)
{
	float input1[50];
	float input;
	int i = 0;

	FILE * inputFile1;
	inputFile1 = fopen("input1.txt","r");

		while(feof(inputFile1)== 0)
		{
			 input1[i] = fscanf(inputFile1,"%f",&input);
			 i++;
		}
		fclose(inputFile1);

	char obuffer[MAX_PIPE_WRITE];
	int len;
	tSend1++;
	if (tSend1 > 50)	return;
	len = sprintf_s(obuffer, MAX_PIPE_WRITE, "Bigger output message : <%f> ", input1[tSend1]);
	printf("OUT1: %s\n", obuffer);
	_write(fdpipe[WRITE], obuffer, len);

You have to understand how fscanf works. Where does it store the result of conversion, and what does it return.
In your case, all the numbers you read end up in input , while input1[] collects return codes (which all happen to be 1, indicating successful conversion of one field).

Comments
very good information

You have to understand how fscanf works. Where does it store the result of conversion, and what does it return.
In your case, all the numbers you read end up in input , while input1[] collects return codes (which all happen to be 1, indicating successful conversion of one field).

Hi nezchem, thanks for your input. I changed my code into

while(feof(inputFile1)== 0)
		{
			 fscanf(inputFile1,"%f",&input[i]);
			 i++;
		}
		fclose(inputFile1);

and magically it works now. Really appreciate your help.

This question has already been answered. Start a new discussion instead.