Read hexadecimal argument from command line


/ Published in: C
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.