Upload files to "file"
This commit is contained in:
parent
fab6d48bab
commit
5b1755747f
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
AUTORE: Manuel Vichi 3^AIN
|
||||||
|
Esercizio 7 File Binari
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
using namespace std;
|
||||||
|
void fChangeEndianness(char * fileName) {
|
||||||
|
FILE *file = fopen(fileName, "rb+");
|
||||||
|
if (!file) {
|
||||||
|
perror("Errore durante l'apertura del file di lettura/scrittura");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uint8_t buffer[4];
|
||||||
|
long pos = 0;
|
||||||
|
while (fread(buffer, 1, 4, file) == 4) {
|
||||||
|
uint8_t tmp;
|
||||||
|
tmp = buffer[0]; buffer[0] = buffer[3]; buffer[3] = tmp;
|
||||||
|
tmp = buffer[1]; buffer[1] = buffer[2]; buffer[2] = tmp;
|
||||||
|
fseek(file, pos, SEEK_SET);
|
||||||
|
fwrite(buffer, 1, 4, file);
|
||||||
|
pos += 4;
|
||||||
|
fseek(file, pos, SEEK_SET);
|
||||||
|
}
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
int main(void) {
|
||||||
|
char file[] = "indiano.bin";
|
||||||
|
fChangeEndianness(file);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue