Witam
mam do napisania funkcję, która konwertuje string na double. Poniżej kod źródłowy
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
struct maybe_double {
bool value_exists;
double value;
};
struct maybe_double parse_float(const char *input) {
struct maybe_double out = {.value_exists = false};
if(strcmp(input,"0.0")==0)
{
out.value_exists=true;
out.value=0.0;
}
else if(strtod(input,NULL)!=0)
{
out.value_exists=true;
out.value=strtod(input,NULL);
}
else if(strtod(input,NULL)==0.0)
out.value_exists=false;
return out;
}
wywala mi dwa błędy w testach:
parse_float("-12-34") should fail
parse_float("-85,.0000") should fail
nie wiem co jest nie tak. Może ktoś pomóc
naliknalik