dumb question, quick solution needed
dumb question, quick solution needed
- Subject: dumb question, quick solution needed
- From: "D.Walsh" <email@hidden>
- Date: Thu, 17 Feb 2005 21:29:37 -0500
- Mta-interface: amavisd-new-2.2.1 (2004-12-22) at daleenterprise.com
Sometimes you forget the simple things, and while brain-freeze has set
in this has me stumped, I thought I could define argv as a long but
this doesn't work.
'theNumber' has to be a long as required by the remainder of the
program (not present) but it appears to be a string, anyone know what
I'm forgetting to do hear?
Here's the front end of the tool, compile with:
gcc src.c -o d2h
To execute: ( first call shows built in test number, second call is how
the tool will be called when in real use)
./d2h
./d2h123
__________________________________________________________
#include <stdio.h>
char *conv_base(long theNumber, int base);
int main (int argc, long argv[]) {
long theNumber;
if (argc == 1){
theNumber = 123;
} else
theNumber = argv[1];
printf("%ld = %s\n",theNumber,conv_base(theNumber,16));
}
char *conv_base(long theNumber, int base)
{
long remain;
int n = 0, k = 0;
static char temp[32], result[32];
static char *digit = "0123456789ABCDEF"; // list of digits
do
{
remain = theNumber % base; // modulo gets remainder
theNumber = theNumber / base; // whittle down theNumber
temp[k++] = digit[remain];
} while (theNumber > 0);
while (k >= 0)
result[n++] = temp[--k]; // spell forward
result[n-1] = 0; // add string EOS
return (result);
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden