Re: hex to int




"Bill Cunningham" <nospam@xxxxxxxxxxxxx> wrote in message
news:49a1ba14$0$5470$bbae4d71@xxxxxxxxxxxxxxxxxxxxxx
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);
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.

Bill

I see that strtol returns a long. Could this be part of the problem?

Bill


.



Relevant Pages

  • Re: hex to int
    ... Input should be a hex number like fff or 0xfff and convert it to the decimal ... int main(int argc, char **argv) ... Keith Thompson kst@xxxxxxx ...
    (comp.lang.c)
  • Re: C File I/O... working with array structures
    ... I've sent you an e-mail of my code and supporting information. ... bio1.c:53: warning: double format, ... but acids.count has type int. ... use, a parameter called argc. ...
    (comp.lang.c)
  • Re: I need HELP!!!
    ... int main(int argc, char** argv) ... probably argc and argv should be omitted from the prototype of main. ... Also, when you are writing out an error message, you would ...
    (comp.lang.c)
  • Re: Newbie question...
    ... int main (int argc, char *argv) ... In this case, gcc uses a register, so I didn't really find ... expectations and made its parents too proud, ...
    (alt.lang.asm)
  • Re: Why is it int argc?
    ... in which the only numeric types were char, int, float, and double. ... argc and argv.) ... main(argc, argv) ... advantage that the lower and upper bounds are both well outside any ...
    (comp.lang.c)