Posted By

vdevos on 03/14/12


Tagged

hex c commandline read hexadecimal argument parsing


Versions (?)

Read hexadecimal argument from command line


 / Published in: C
 

This piece of code will read a hex argument such as: ff or ab from your command line and stores it as a integer

  1. /*
  2.   IN: program ff aa
  3.   OUT: Values: ff, aa
  4. */
  5.  
  6. int main (int argc, char *argv[]) {
  7.  
  8. unsigned int values[2];
  9.  
  10. values[0] = strtol(argv[1], NULL, 16);
  11. values[1] = strtol(argv[2], NULL, 16);
  12.  
  13. printf("Values: %x, %x", values[0], values[1]);
  14. }

Report this snippet  

You need to login to post a comment.