Re: hex to int
- From: "Joachim Schmitz" <nospam.jojo@xxxxxxxxxxxxxxxxxx>
- Date: Sun, 22 Feb 2009 21:53:36 +0100
Bill Cunningham wrote:
I have written this small program and I must admit I'm a little
stuck. Input should be a hex number like fff or 0xfff and convert it
to the decimal equivalent. The output I get is always 0.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
if (argc != 2) {
puts("hex usage error");
exit(EXIT_FAILURE);
}
int x = strtol(argv[1], NULL, 10);
that 3rd argument should be 16
printf("%i\n", x);
return 0;
}
Am I missing a std function here that could do this for me? I know
error checking is not present.
http://linux.die.net/man/3/strtol
If there were no digits at all, strtol() stores the original value of nptr in *endptr (and returns 0).
Bill
.
- Follow-Ups:
- Re: hex to int
- From: Bill Cunningham
- Re: hex to int
- References:
- hex to int
- From: Bill Cunningham
- hex to int
- Prev by Date: Re: hex to int
- Next by Date: Re: hex to int
- Previous by thread: Re: hex to int
- Next by thread: Re: hex to int
- Index(es):
Relevant Pages
|