68 lines
1.7 KiB
C
68 lines
1.7 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdint.h>
|
|
|
|
typedef struct {
|
|
uint8_t octet1;
|
|
uint8_t octet2;
|
|
uint8_t octet3;
|
|
uint8_t octet4;
|
|
} quartet;
|
|
|
|
int main ( int argc, char **argv)
|
|
{
|
|
printf("start main");
|
|
int i;
|
|
char buff[26];
|
|
char buff2[18];
|
|
int32_t values[8];
|
|
uint32_t valbin[8];
|
|
quartet value;
|
|
FILE* test = fopen("02400001.TXT","r");
|
|
if(test == NULL){
|
|
printf("File NULL");
|
|
return 1;
|
|
}
|
|
if(!test){
|
|
printf("File opening failed");
|
|
return 1;
|
|
}
|
|
printf("\nbefore while");
|
|
while (fread(&buff, 26, 1, test)) { //stdin à la place de test de basetest
|
|
/*buff[25] = '\0';*/
|
|
if (strncmp(buff, "#################\n", (size_t)18) == 0) {
|
|
if (!(fread(&buff2, 18, 1, test))) { // stdin here too
|
|
fprintf(stderr, "Erreur lesture après ###...#");
|
|
return(1);
|
|
} else {
|
|
/*buff2[17] = '\0';*/
|
|
strncpy(buff, &buff[18], 8);
|
|
strncpy(&buff[8], buff2, 18);
|
|
}
|
|
}
|
|
i = 3;
|
|
value.octet1 = buff[3*i+1];
|
|
value.octet2 = buff[3*i+2];
|
|
value.octet3 = buff[3*i+3];
|
|
value.octet4 = 0;
|
|
/*memcpy(&values[i], &value, sizeof(quartet));*/
|
|
|
|
valbin[i] = buff[3*i+1]*256*256*256 + buff[3*i+2]*256*256 + buff[3*i+3]*256;
|
|
memcpy(&values[i], &valbin[i], sizeof(int32_t));
|
|
if (value.octet1 & 0b10000000) {
|
|
printf("Valeur negative trouvee: %02x %02x %02x %d\n", value.octet1, value.octet2, value.octet3, values[i]);
|
|
}
|
|
|
|
printf("%02x %02x %02x %d", value.octet1, value.octet2, value.octet3, values[i]/256); // stdout au début du printf
|
|
|
|
/*
|
|
for (i=1; i<25; i++) {
|
|
fprintf(stdout, "%02x ", buff[i]);
|
|
}
|
|
|
|
*/
|
|
printf("\n");
|
|
}
|
|
// printf("\nend");
|
|
}
|