Hello everyone,

I'm working on a project, each time two numbers are read from a text file. Text file contains two lines of sequational numbers, something like this:

4 5 2 1 10 8
3 4 6 1

I have two linklists and each node is able to store two numbers. First line should be stored in the first linklist, whereas second line in the second one. I should use newline character as a seperator to determine which line goes to which linklist.

I'm stuck at this point because I couldn't find a way to use newline character to change the function so that new numbers will be passed to second linklist's insert function. The following one detects the newline successfully but I couldn't put it into practice.

I'm hopeless and need to submit in 12 hours... Please help me :(

while(!feof(text))
{
	fscanf(text,"%d",&num);
	fscanf(text,"%d",&num2);
	detect=fgetc(text);
	if(detect=='\n')
	{
		printf("New line!");
	}

}

I've solved the problem. For those who may need the same solution, here is the code I've used: (If you have better idea, please let me know)

.
.
.
char detect;
while(!feof(polyFile))
	{
		fscanf(polyFile,"%d",&copy.num);
		fscanf(polyFile,"%d",&copy.num2);
		//PASS TO THE FIRST LINKLIST
		detect=fgetc(polyFile); //Triggered when a new line is found.
		if(detect=='\n')
			break;

	}

while(!feof(polyFile))  //It'll continue from the second line
	{
		fscanf(polyFile,"%d",&num);
		fscanf(polyFile,"%d",&num2);
		//PASS TO THE SECOND LINKLIST
	}

while(!feof(polyFile)) >I've solved the problem

feof() is never a solution to control a loop. Read here why.

while(!feof(polyFile)) >I've solved the problem

feof() is never a solution to control a loop. Read here why.

Thank you for the reply, but prevent from this error, i always check if EOF is set at the end of last word. I mean, by deleting new line and use backspace to return at the end of the latest word, and save it. So there no error encounters, but though, thank you for letting me know what the peoblem was since I've tried to solve it with my own solution.

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