Endianness refers to BYTE ordering within data types, hence your question is vague.
If it's some sort of binary file, you need to read every structure in and reverse the BYTES in it, then serialize back to disk. If it's some sort of multibyte text file you need to lookup the encoding and act accordingly.
sidenote: If you want to swap pairs of bytes in a file use dd with
conv=swab
LE: try this for just reversing everything:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
FILE* input = NULL;
FILE* output = NULL;
unsigned long size = 0;
unsigned long itr = 0;
unsigned char* buffer;
if(argc != 3)
return 0;
input = fopen(argv[1],"rb");
output = fopen(argv[2],"wb");
if(!input || !output)
fprintf(stderr,"could not open file");
fseek(input,0,SEEK_END);
size = ftell(input);
fseek(input,0,SEEK_SET);
buffer = (unsigned char*)malloc(size);
fread(buffer,1,size,input);
fclose(input);
for(itr = size;itr>0;itr--)
{
fwrite(&buffer[itr-1],1,1,output);
}
fclose(output);
return 0;
}
compile and use like this:
./application inputfile outputfile