c - How should i limit the number of characters interpretted by fscanf? -


i'm writing program read stdin , writes reads stdout, unescaping escaped hex numbers finds. numbers want read 8 bit. have far

while((c = fgetc(stdin)) != eof) {     if(c == '%') {         fscanf(stdin,"%x",&r);         printf("%i \n",r);     } } 

this works fine, except fact when write %fff standard input reads 3 digit hex number. how should limit fscanf reading 2 characters? have thought reading next 2 characters buffer , sscanf'ing that, feels rather inelegant me.

if want scanf (et al) read 2 characters, tell so:

scanf("%2x", &r); 

see e.g. this reference information scanf formatting.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -