I was trying to read in data from a txt file. The txt file has multiple entries each occupies a new line, and each entry has variable length of hex byte data delimited by some symbols (say space ' '). A sample txt file looks like the below
e4 e2 e2 e1 ff\n
f2 a2 22 34\n
ff ee dd\n
Using scanf(fp,"%2x",buffer+offset) in a loop, I was trying to load each byte into a byte buffer until the end of each line, marking a complete record. The main problem is to detect the newline character as scanf ignores it completely and jump into the next line. My original code was
do{
counter=fscanf(datain,"%2x",buffer1+offset);
fprintf(stdout,"%#2x ",buffer1[offset]);
offset+=counter;
}while(!feof(datain));