1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
string demandeLeChemin(void)
{
string chemin;
cout << "Entrez le chemin d'accès au fichier\n";
cin >> chemin;
return chemin;
}
ifstream message; // message object
int entier;
double decimal;
char caractere;
int main( int argc, char** argv )
{
int n=0,i=0;
char c[10000];
int flag_byte=0;
unsigned char bit[200000];
if (argc == 1)
{
do
{
message.open(demandeLeChemin());
}
while (!message);
cout << message;
do
{
/*cette fonction prend en paramètre un fichier ou flux, et renvoi un caractère
la premiere fois qu'elle est apelé elle revoi le 1er caractère, la deuxième fois elle revoit le deuxième, ect...,
Ensuite sur chaque octet, tu peut aisément lire la suite des 8 bits en utilisant des masques binaires.*/
c[i++] = fgetc (message); // NE MARCHE PAS COMMENT FAIRE POUR CONVERTIR UN FSTREAM EN FILE* ???
if (c[i] & 0x01 == 0x01)
{
cout << 1;
bit[flag_byte] = 1;
}
else
{
cout << 0;
bit[flag_byte] = 0;
}
if (c[i] & 0x02 == 0x02)
{
cout << 1;
bit[flag_byte+1] = 1;
}
else
{
cout << 0;
bit[flag_byte+1] = 0;
}
if (c[i] & 0x04 == 0x04)
{
cout << 1;
bit[flag_byte+2] = 1;
}
else
{
cout << 0;
bit[flag_byte+2] = 0;
}
if (c[i] & 0x08 == 0x08)
{
cout << 1;
bit[flag_byte+3] = 1;
}
else
{
cout << 0;
bit[flag_byte+3] = 0;
}
if (c[i] & 0x10 == 0x10)
{
cout << 1;
bit[flag_byte+4] = 1;
}
else
{
cout << 0;
bit[flag_byte+4] = 0;
}
if (c[i] & 0x20 == 0x20)
{
cout << 1;
bit[flag_byte+5] = 1;
}
else
{
cout << 0;
bit[flag_byte+5] = 0;
}
if (c[i] & 0x40 == 0x40)
{
cout << 1;
bit[flag_byte+6] = 1;
}
else
{
cout << 0;
bit[flag_byte+6] = 0;
}
if (c[i] & 0x80 == 0x80)
{
cout << 1;
bit[flag_byte+7] = 1;
}
else
{
cout << 0;
bit[flag_byte+7] = 0;
}
flag_byte += 8;
if (c[i] == 'e') n++;
}while (c[i] != EOF);
cout << "Il y a "<< n <<" fois le caractère 'e' dans ton message.\n";
message.close();
/*
00000001b = 0x01 = 1
00000010b = 0x02 = 2
00000100b = 0x04 = 4
00001000b = 0x08 = 8
00010000b = 0x10 = 16
00100000b = 0x20 = 32
01000000b = 0x40 = 64
10000000b = 0x80 = 128
*/
return 0;
}
else
{
// not OK : main returns -1
return -1;
}
} |
Partager