why is this C++ Code not doing his job
- by hamza
i want to create a program that write all the primes in a file ( i know that its a popular algorithm but m trying to make it by my self ) , but it still showing all the numbers instead of just the primes , & i dont know why someone pleas tell me why
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
void afficher_sur_un_ficher (FILE* ficher , int nb_bit );
int main()
{
FILE* p_fich ;
char tab[4096] , mask ;
int nb_bit = 0 , x ;
for (int i = 0 ; i < 4096 ; i++ )
{
tab[i] = 0xff ;
}
for (int i = 0 ; i < 4096 ; i++ )
{
mask = 0x01 ;
for (int j = 0 ; j < 8 ; j++)
{
if ((tab[i] & mask) != 0 )
{
x = nb_bit ;
while (( x > 1 )&&(x < 16384))
{
tab[i] = tab[i] ^ mask ;
x = x * 2 ;
}
afficher_sur_un_ficher (p_fich , nb_bit ) ;
}
mask = mask<<1 ;
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);
}