von moonangel » Sa 07 Okt, 2006 17:59
gut okay funkt jetzt super aber wie schreib ich so um
das der benutzer die zahl die anfangsbasis und die zeilbasis
eingeben kann ?
/*
#include "stdafx.h"
#include<stdlib.h>
double my_strtol(char *zahl, unsigned int base) ;
int main()
{
unsigned int x;
x = my_strtol("2da", 16); //was das? wie geb ich ein ?
printf("%u\n", x);
return 0;
}
static unsigned int basedig(unsigned char dig, unsigned int base) {
if (dig >= '0' && dig <= '9')
return dig - '0'; // was is dig?
else if (dig >= 'a' && dig <= 'z') //was is else if?
return dig - 'a' + 10;
else if (dig >= 'A' && dig <= 'Z')
return dig - 'A' + 10;
return -1;
}
double my_strtol(char *zahl, unsigned int base)
{
unsigned int ret, dig;
double nc, fact, exp;
unsigned char *cp;
if (!zahl || base < 2 || base > 36)
return -1;
ret = 0;
nc = 0;
fact = 1; // fact = variable?
cp = (unsigned char *) zahl;
while (*cp == ' ')
cp++;
if (*cp == '-') {
fact = -1;
cp++;
}
while (*cp) {
dig = basedig(*cp, base); // was is basedig?
if (dig == -1)
break;
if (dig >= base)
break;
ret *= base;
ret += dig;
cp++;
}
if (*cp == '.') {
cp++;
exp = base;
while (*cp) {
dig = basedig(*cp, base);
if (dig == -1)
break;
if (dig >= base)
break;
nc += dig / exp;
exp *= base;
cp++;
}
}
return fact * (nc + ret); // was hat man mir eigentlich beigebracht ??
}
*/