82 lines
1.6 KiB
C
82 lines
1.6 KiB
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
typedef unsigned char BYTE;
|
||
|
|
||
|
int stringToByte(char* input, BYTE* output){
|
||
|
|
||
|
int i;
|
||
|
int loop;
|
||
|
|
||
|
loop = 0;
|
||
|
i = 0;
|
||
|
while (input[loop] != '\0'){
|
||
|
//printf("output : %d input : %d /", output[i], input[i]);
|
||
|
output[i] = input [loop];
|
||
|
i++;
|
||
|
loop++;
|
||
|
//printf("output2 : %d input2 : %d\n", output[i],input[i]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
long long convert(int n) {
|
||
|
long long bin = 0;
|
||
|
int rem, i = 1;
|
||
|
|
||
|
while (n!=0) {
|
||
|
rem = n % 2;
|
||
|
n /= 2;
|
||
|
bin += rem * i;
|
||
|
i *= 10;
|
||
|
}
|
||
|
|
||
|
return bin;
|
||
|
}
|
||
|
|
||
|
int main (int argc, char **argv){ // **argv ou *argv[]
|
||
|
|
||
|
FILE* flux;
|
||
|
|
||
|
int longueurInstru;
|
||
|
|
||
|
int i;
|
||
|
|
||
|
int a[10];
|
||
|
|
||
|
int c,k,y=0;
|
||
|
|
||
|
int test;
|
||
|
|
||
|
BYTE *instruction = malloc(64*sizeof(int));
|
||
|
BYTE arr[50];
|
||
|
|
||
|
flux= fopen(argv[1], "r");
|
||
|
|
||
|
if (flux == NULL){
|
||
|
perror("fopen");
|
||
|
return EXIT_FAILURE;
|
||
|
}
|
||
|
|
||
|
if (flux){
|
||
|
while (fscanf(flux, "%[^\n] ", instruction) != EOF) {
|
||
|
longueurInstru = strlen(instruction);
|
||
|
stringToByte(instruction, arr);
|
||
|
for (i=0; i<longueurInstru; i++){
|
||
|
for (y=0; y<longueurInstru; y++){
|
||
|
printf("%c", instruction[y]);
|
||
|
}
|
||
|
printf("\n");
|
||
|
test=arr[i];
|
||
|
test=convert(test);
|
||
|
printf("Instruction : %c / Int : %d / Binaire : %lld\n\n", instruction[i], instruction[i], test);
|
||
|
// mettre tout sur une même ligne puis écrire dans un fichier
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
fclose(flux);
|
||
|
|
||
|
}
|
||
|
// à faire : entrer ça dans un fichier
|
||
|
// puis faire un programme qui interprète les commandes et la transforme en format conforme puis remettre dans un fichier
|