Over a million developers have joined DZone.

[C] - Read Hex Argument From Console Into Integer

·
// This code Reads a hexadecimal argument from the commandline and puts it into a integer


 
  
 //  INPUT:   ./prog ff aa
 //  OUTPUT:  hex_values: ff and aa

 int main (int argc, char *argv[]) {
   
   int hex_values[2];
   hex_values[0] = strtol(argv[1], NULL, 16);
   hex_values[1] = strtol(argv[2], NULL, 16);
 
   printf("hex_values: %x and %x", hex_values[0], hex_values[1]); 
 }

Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}