0

Hello,

I am really new to writing C code. I am generally written Java code all my life, so I am struggling with C code as this is the second program I am writing in C.

I am trying to read a txt file that has numbers in the format of

12
145
156
1263
1342
1642

I am trying to read these in and storing them into my array. I tried two different ways, but it's not working. The loop just runs forever and prints 0s and random values.

while((fscanf(file, "%d\n", &allInstructs[count]) != EOF))
		{
			printf("Running %d\n", allInstructs[count]);
			count++;
		}

Thanks again!

Edited by WaltP: Fixed CODE Tags

2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by N1GHTS
0

You are asking fscanf for a %d, which is a decimal integer. You are giving it a pointer. The random numbers are probably pointers getting resolved to decimal integers. Looks like you did it correctly in the printf function.

Not sure why you got two sets of parenthesis around your while expression. Doesn't hurt anything but can be confusing if you were to add more logic to it.

Keep in mind this advice is probably not entirely accurate since you are only showing a tiny piece of the code and I am trying to fill in the blanks.

Edited by N1GHTS: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.