Hi,
I'm new here and first one thing... is there any way that i can receive the messages from the board by e-mail???
And now the real reason of this message...
I have a problem using atof() and i can't undestand what's happening since i have a struct and i have used it already with floats and i had no problem... but now when the function begins i receive a message from the watch box telling it's an illegal use of floating points... ( I have tried to change the way i get the string but it didn't work anyway... i have gotten out the NULL char at the end of the string and nothing, i have changed a lot of things but nothing seems to work out... and i didn't find any useful help in the board yet... can someone help me PLEASEEEEEEEE!!!!
This function will get the information from the keyboard to make me able of doing some operations without knowing how many arguments will be typed
here goes the code:
Code:
#define ENTER 13
#define MAXS 6
#define INTGR 1
#define FLT 2
#define STRG 3
typedef struct tokens{
int telem;
union { int ielem;
float felem;
char opelem;
} tokelem;
}*TOKEN;
TOKEN GetToken (void) {
char c;
TOKEN tok=NULL;
char S[MAXS];
int i = 0;
float fl;
c = getche();
while ( c == ' ') c=getche();
while ( (c != ' ' ) && (c!= ENTER) ){
if (c>='0'&& c<='9'){
while ( c!=' '){
S[i]=c;
i++;
c=getche();
}
S[i]='/0';
tok = malloc (sizeof(struct tokens));
if (strstr(S,".") == NULL ) {
tok->telem = 1;
tok->tokelem.ielem = atoi(S);
}
else {
tok->telem = 2;
fl = atof(S);
tok->tokelem.felem = fl;
}
return tok;
}
else
switch ( c ) {
case '+':
case '-':
case '/':
case '*': tok->telem = 3;
tok->tokelem.opelem = c;
return tok;
default : GetToken(); break;
}
}
tok = NULL;
return tok;
}
Code Tags added by Kermi3