raghavkmr
Junior Member level 2
Hi i want to read alphanumeric characters from a text file and put them as hexadecimal characters in a variable
for e.g.
uint8_t *output;
*output = 0xFA ;
it works
but instead i want to read alphanumeric code from a file containing
FA
1B
2E
ED
but when i read values from file and put it into output variable i found that output takes ascii value of first character.
for e.g. 1B
output gets 31 (ascii for 1) instead of 1B what should i do
for e.g.
uint8_t *output;
*output = 0xFA ;
it works
but instead i want to read alphanumeric code from a file containing
FA
1B
2E
ED
but when i read values from file and put it into output variable i found that output takes ascii value of first character.
for e.g. 1B
output gets 31 (ascii for 1) instead of 1B what should i do
Code:
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
int main() {
uint8_t *output ;
unsigned char x ;
char c;
FILE *fp1, *fp2;
FILE *f_gets = fopen("key_bank_ssl.key", "r");
if(f_gets==NULL)
{
printf("Please point to a valid key file!\n");
fclose(f_gets);
return 0;
}
char str[2];
if( fgets (str, 3, f_gets)!=NULL ) {
/* writing content to stdout */
puts(str);
output = (uint8_t *)(str);
puts(output);
printf("\noutput %s --- %02x --> size --> %lu",str,*output++,sizeof(*output));
}
fclose(f_gets);
}