ok, that is what I've done so far. Is there anything I can optimize? One prob is left: I'd like to call int2hex even if there is no , at the end of the input string (e.g. 78, 10); is there a way I can manage this?
Thanks...
Code:
//Calculate Int 2 Hex from String
#include <stdio.h>
#include <stdlib.h>
void int2hex(int number){
char hexdigit[] = "0123456789ABCDEF";
char hexnum[7];
char buffer;
int i = 0;
while(number){
buffer = hexdigit[(number % 16)];
number /= 16;
hexnum[i++] = buffer;
}
char result[i];
int l;
for(l = i-1; l >=0; l--){
result[l] = hexnum[l];
printf("%c", result[l]);
}
//here: Print(result);
}
void filter(char *string){
int decimal = 0;
while(*string){
if(*string == ','){
int2hex(decimal);
decimal = 0;
}
else if(*string == ' '){
}
else{
decimal = decimal*10 + (*string - '0');
}
*string++;
}
}
int main(int argc, char *argv[]){
char string [8] = {'7','8',',',' ','1','0',','};
//int2hex(10000);
filter(string);
system("PAUSE");
return 0;
}