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
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* readFileBytes(const char *name, int* sz)
{
FILE *fl = fopen(name, "rb");
if(fl == NULL){
printf("Error while opening %s", name);
exit(EXIT_FAILURE);
}
fseek(fl, 0, SEEK_END);
long len = ftell(fl);
*sz = len;
char *ret = (char*) malloc(len);
fseek(fl, 0, SEEK_SET);
fread(ret, 1, len, fl);
fclose(fl);
return ret;
}
int main(){
int* len;
/*unsigned*/ char *array = readFileBytes("C:\\test.txt", len);
//int len = strlen(array);
int i = 0;
//printf("%d", *len);
//exit(0);
for (i; i < *len; i++)
{
printf("%X ",array[i]);
}
free(array);
return 0;
}
|