Hi i am trying to read two characters from a file and want to send it to uint8_t* as hexadecimal . Code:
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
int file_handling();
int main()
{
uint8_t *output ;
output=file_handling() ;
printf("\noutput_main --> %02x",output);
}
int file_handling()
{
uint8_t *output_hand ;
char c;
FILE *f_gets = fopen("filename", "r");
if(f_gets==NULL)
{
printf("Please point to a valid key file!\n");
fclose(f_gets);
return 0;
}
char str[3];
if( fgets (str, 3, f_gets)!=NULL )
{
/* writing content to stdout */
puts(str);
output_hand = (uint8_t *)(str);
puts(output_hand);
printf("\noutput %s --- %02x --> size --> %lu",str,*output_hand,sizeof(*output_hand));
}
fclose(f_gets);
return *output_hand;
}
following is output
we we
output we --- 77 --> size --> 1 output_main --> 65
what i can understand is 77 is ascii for w and 65 is ascii for e
but i want to put "we" which i suppose is a hex in uint8_t *output where is the problem in main ,if i use pointer "*output=file_handling()" instead of just output i get segmentation fault.
How to read value from a file and put it into uint8_t , where file is having hex characters,how fget identifies it as hex or char.
Thanks
file is a text file
ab
fe
ea
ce
1d
Basically uint8_t *output; *output = 0xFA ; it works but i want to read from above file and put it into output variable