i want to create a program that write all the primes in a file ( i know that its a popular algorithm "Sieve of Eratosthenes" but m trying to make it by my self ) i m trying to eliminate all the complications for the bites that still have the value 1 then wrote them in a File
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
void afficher_sur_un_ficher (FILE* ficher , int nb_bit );
char el_mask (int x );
int main()
{
FILE* p_fich ;
char tab[4096] , mask , eli_mask ;
int nb_bit = 0 , x , f ;
for (int i = 0 ; i < 4096 ; i++ )
{
tab[i] = 0xff ;
}
for (int i = 0 ; i < 4096 ; i++ )
{
for (mask = 0x01 ; mask != 0 ; mask<<=1 )
{
if ((tab[i] & mask) != 0 )
{
x = nb_bit ;
while (( x > 1 )&&(x < 16384))
{
eli_mask = el_mask(x);
f = x / 8 ;
tab[f] = tab[f] ^ eli_mask ;
x = x + nb_bit ;
}
afficher_sur_un_ficher (p_fich , nb_bit ) ;
}
nb_bit++ ;
}
}
system ("PAUSE");
return 0 ;
}
void afficher_sur_un_ficher (FILE* ficher , int nb_bit )
{
ficher = fopen("res.txt","a+");
fprintf (ficher ,"%d \t" , nb_bit);
int static z ;
z = z+1 ;
if ( z%10 == 0)
fprintf (ficher , "\n");
fclose(ficher);
}
char el_mask (int x )
{
x = x%8 ;
switch (x)
{
case 0 :
x = 0b00000001 ;
break ;
case 1 :
x = 0b00000010 ;
break ;
case 2 :
x = 0b00000100 ;
break ;
case 3 :
x = 0b00001000 ;
break ;
case 4 :
x = 0b00010000 ;
break ;
case 5 :
x = 0b00100000 ;
break ;
case 6 :
x = 0b01000000 ;
break ;
case 7 :
x = 0b10000000 ;
break ;
}
return x ;
}