I am trying to covert a string to an ascii code in rust to turn the string into BrainFuck code:
(The varable "input" is the string "hello" and this snippet starts at line 12)
for x in input.chars(){
ascii = x as u8;
println!("{}", ascii);
if ascii > 86 {
target = ascii - 86;
output = output.clone() + "+[--------->++++++<]>";
for x in 0..target{
output = output + "+";
output = output + ".>";
}
}else if ascii <= 86 {
println!("{}", ascii);
target = ascii - 86;
output = output.clone() + "+[--------->++++++<]>";
for x in 0..target{
output = output + "-";
output = output + ".>"
}
}
}
println!("{}", output)
However, the program fails with an 'attempt to subtract with overflow' at 25:16. This was unusual so I printed out all of the ascii values and got:
104
101
108
108
111
10
10
I am not sure why the two extra 10's are there, but they seem to be causing this subtract overflow. Why are these 10's being put into the ascii varable? Could it be that I am technically converting a string to base 10 and rust puts them there by default?