1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #include <stdio.h>
#include <stdlib.h>
#define BUFFSIZE 256
int main(void)
{
char const chaine[] = "CAL_KJL = 1.0000000e+001 . (tolerance )";
char seps[] = " ,\t\n=";
char *token;
int ret;
char temp[BUFFSIZE];
double n;
token = strtok( chaine, seps );
while( token != NULL ) {
// While there are tokens in "string"
printf( " token vaut:%s\n", token );
ret = sscanf (token, "%[0-9-]s",temp);
printf("temp vaut: %g\n",temp);
if (ret!=0){
double n = strtod (temp, NULL);
}
printf ("n = %.2f\n", n);
printf ("n = %g\n", n);
token = strtok( NULL, seps );
}
return 0;
} |