I'm talking about your algorythm. Is the whole algorythm about copying?
Printable View
I'm talking about your algorythm. Is the whole algorythm about copying?
Good :) Sorry, for being suspicious, but some users just copy paste someone's code and come here pretending it is theirs.. How could someone do this and feel right???
Anyway, in my example, you just open two files, like you have done nicely in your code too.
Then it reads the 1st line and will write this 1st line (from the source file) to the output file.
Then it reads the 2nd line and will write this 2nd line (from the source file) to the output file.
It will keep doing the same, until EOF is reached.
Then we close both file pointers.
Notice, that in my example, we copy all the data of the source file to the output file. In your case you want to read data, do the prime thing and then write the b array in the output file.
So, I suggest you to do the prime job inside a loop (where you will read a line per loop from the source file) and within that loop you will fill your array b.
Then when the loop is terminated, thus we reached EOF, you will call fwrite just once and write the whole array b in the output file (just with one call).
Also declare the array b outside the loop.
Hint:
For this loop not to be infinite (assuming it is entered), then either a, i, a[i], or j is going to have to change inside the loop.Quote:
Code:while ((a[i]% j) == 0)