File operations
/*
==========================================================
Title: Print the prime number within 1000 to the D-disk "prime number. txt".
==========================================================
*/
#include <stdio.h>
void Main ()
{
FILE *FP;
int n,i,k,m=0;
Fp=fopen ("d:\\ prime number. txt", "w");
if (fp==null)
printf ("Can not open!\n");
Else
{
for (n=2;n<1000;n++)
{
K=int (N/2);
for (i=2;i<=k;i++)
if (n%i==0)
Break
if (i>k)
{
printf ("%5d", N);
m++;
fprintf (FP, "%4d", N);
if (m%10==0)
{
fprintf (FP, "\ n");
printf ("\ n");
}
}
}
}
Fclose (FP);
printf ("\ n");
}
/*
==========================================================
Comment: File operation basic problem, first define pointer to the file *FP, make it point to the target
File, W indicates writable. Then write the prime number program, and back to the basic algorithm!
==========================================================
*/
Copyright Notice: Bo Main article can be reproduced non-commercial, but please be sure to indicate the source, because the level is limited, inevitably error, in this disclaimer.
C language File operations 01--printing of prime numbers to files within 1000