Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

[C] - Read Hex Argument From Console Into Integer

DZone's Guide to

[C] - Read Hex Argument From Console Into Integer

·
Free Resource
// 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:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}