B
Bill Cunningham
Well I read 5.10 page 114 and didn't learn a thing. I wrote some code
the compiled with warnings. This program is supposed to take an h or NULL as
its first argument and if there's no h as the first arg it subtacts
decimals. If there's an h subtracts hex numbers. The ouput I get is 0.00 or
segmentation fault. What a mess.
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv)
{
int i;
long a, b;
double x, y;
if (argv[1] != 'h') {
x = strtod(argv[2], NULL);
y = strtod(argv[3], NULL);
printf("%.2f\n", x - y);
} else if (argv[1] == 'h') {
a = strtol(argv[2], NULL, 16);
b = strtol(argv[3], NULL, 16);
printf("%ld\n", a - b);
}
return 0;
}
embarrassing or not I would like the 'h' to show up as any argv[] whether 1
or 3 if hex subtraction. If it's not present decimal subtraction.
Bill
the compiled with warnings. This program is supposed to take an h or NULL as
its first argument and if there's no h as the first arg it subtacts
decimals. If there's an h subtracts hex numbers. The ouput I get is 0.00 or
segmentation fault. What a mess.
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv)
{
int i;
long a, b;
double x, y;
if (argv[1] != 'h') {
x = strtod(argv[2], NULL);
y = strtod(argv[3], NULL);
printf("%.2f\n", x - y);
} else if (argv[1] == 'h') {
a = strtol(argv[2], NULL, 16);
b = strtol(argv[3], NULL, 16);
printf("%ld\n", a - b);
}
return 0;
}
embarrassing or not I would like the 'h' to show up as any argv[] whether 1
or 3 if hex subtraction. If it's not present decimal subtraction.
Bill