-
Notifications
You must be signed in to change notification settings - Fork 307
/
aaa.c
executable file
·55 lines (49 loc) · 7.4 KB
/
aaa.c
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
double zend_string_to_double(const char *number, int length) /* {{{ */
{
double divisor = 10.0;
double result = 0.0;
double exponent;
const char *end = number+length;
const char *digit = number;
if (!length) {
return result;
}
while (digit < end) {
if ((*digit <= '9' && *digit >= '0')) {
result *= 10;
result += *digit - '0';
} else if (*digit == '.') {
digit++;
break;
} else if (toupper(*digit) == 'E') {
exponent = (double) atoi(digit+1);
result *= pow(10.0, exponent);
return result;
} else {
return result;
}
digit++;
}
while (digit < end) {
if ((*digit <= '9' && *digit >= '0')) {
result += (*digit - '0') / divisor;
divisor *= 10;
} else if (toupper(*digit) == 'E') {
exponent = (double) atoi(digit+1);
result *= pow(10.0, exponent);
return result;
} else {
return result;
}
digit++;
}
return result;
}
int main(){
char *s = "Accept-Language: da, en-gb;q=0.8, en;q=0.7";
char *qvalue;
float qval = (float)zend_string_to_double(qvalue + 2, seg - qvalue + 2);
printf("%f", qval);
return 0;
}