View Single Post
Old 02-07-2014, 08:45 PM   #26
Mighty Midget
Pox Vobiscum
 
Mighty Midget's Avatar


 
Join Date: Mar 2006
Location: Krakeroy, Norway
Posts: 3,014
Default

I need to ask again:

This time, I'm trying to write a code (C) that will generate prime numbers. Thing is, all the sample code I've seen checks each number up against all other, lower, natural numbers but the point is, that is not necessary and in fact will save me a LOT of time as the primes get larger if I only check up against the lower primes I generate.

The idea is to write the primes to a txt file (since 10,000,000,000 primes can take up a lot of memory), and read this list to check the candidate number.

Problem is: I use fscanf and it really isn't playing ball. Either it reads the entire list as one number or it stops reading as soon as it hits a space or new line.

Is there a neat way of reading each number in the list while allowing for space and new line?

Also, is there a way to jump straight to the last number in the list instead of having to go through the entire nightmare everytime I want to resume the job?

The idea here is, when I want to resume the job after a break, I want the program to pick the last prime found + 1 as the new candidate.
__________________
Je Suis Charlie

Last edited by Mighty Midget; 02-07-2014 at 08:49 PM.
Mighty Midget is offline                         Send a private message to Mighty Midget
Reply With Quote