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!

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.