Hello, I have recently started programming again, and right now everything I do is "printf" to the screen. If I want everything to go to a file, say for 1 or 10 million numbers below, could you please tell me how? I have done fread and fwrite OK, but I need more help.
Thank you.
Jim Devaney
/* Copyright (c) 1990, 1992, Borland International */
#include <stdio.h>
#include <conio.h>
#include <time.h>
long prime(long n)
{
long l;
if (n % 2 == 0)
return (n==2);
if (n % 3 == 0)
return (n==3);
if (n % 5 == 0)
return (n==5);
for (l=7; l*l <= n; l+=2)
if (n % l == 0)
return 0;
return 1;
}
void main(void)
{
long int l, n;
time_t s, t;
time(&s);
n = 1000000L;
for (l=2; l<=n; l++) {
if (l % 100000 == 0)
getch();
if (prime(l))
printf("%ld ", l);
}
time(&t);
printf("\nToday's date and time: %s\n", ctime(&s));
printf("Today's date and time: %s\n", ctime(&t));
getch();
}