I am trying to read the contents of a file (which contains both 'standard' text and 'binary' data).
I then need to take that character (standard or extended ASCII) and get the corresponding Decimal (int) ASCII value.
I am having a heck of time getting it to work correctly.
Here is a snippet of the code to help show what I am currently doing...
FILE *fp = fopen(file, "r+");
char *value = NULL;
size_t charSize = sizeof(char) + 1;
value = malloc(charSize);
strcpy(value, "0");
fseek(fp, offset, SEEK_SET);
fgets(value, charSize, fp);
int c = (int)value;
free(value);
I read a thing that was saying that you needed to use an unsigned char for the extended ascii, however changing to unsigned char didn't solve the problem (and gave compile warnings)
I also tried using wchar_t with the code:
....
wchar_t *value = NULL;
value = malloc(2);
wcscpy(value, (wchar_t *)"");
fseek(fp, offset, SEEK_SET);
fgetws(value, 2, fp);
int c = (int)value;
None of these seem to work. I either get a 0 for basically everything, or some 'random' value.
For example using any of the three I get: value: % (correct) c: 76678304 (number is different each time but in this same 'range')(something tells me this isn't correct) :)
So I am obviously doing something wrong but I just can't seem to figure it out...
Any help would be very much appreciated.