B
Bill Cunningham
I re-wrote this code today from what I posted yesterday and finally got
what I wanted! I had to add argc==0 to print something and exit otherwise I
was getting a seg fault.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
if (argc > 3 || argc == 1) {
puts("hexideci usage error");
exit(EXIT_FAILURE);
}
if (argv[1][0] == '-' && argv[1][1] == 'd' && argv[1][2] == '\0') {
long y = strtol(argv[2], NULL, 10);
printf("%x\n", y);
exit(EXIT_SUCCESS);
}
long x = strtol(argv[1], NULL, 16);
printf("%i\n", x);
return 0;
}
Bill
what I wanted! I had to add argc==0 to print something and exit otherwise I
was getting a seg fault.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
if (argc > 3 || argc == 1) {
puts("hexideci usage error");
exit(EXIT_FAILURE);
}
if (argv[1][0] == '-' && argv[1][1] == 'd' && argv[1][2] == '\0') {
long y = strtol(argv[2], NULL, 10);
printf("%x\n", y);
exit(EXIT_SUCCESS);
}
long x = strtol(argv[1], NULL, 16);
printf("%i\n", x);
return 0;
}
Bill