Fix number input non-convertible crash
This commit is contained in:
parent
8beb95963d
commit
731c558a3f
1 changed files with 8 additions and 0 deletions
8
main.cpp
8
main.cpp
|
@ -134,6 +134,14 @@ count_type get_number(string prompt) {
|
||||||
print_input(prompt+": " + s);
|
print_input(prompt+": " + s);
|
||||||
ch = getch();
|
ch = getch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if input is a number
|
||||||
|
for(int i = 0; i < s.size(); i++)
|
||||||
|
if(s[i] < '0' || s[i] > '9')
|
||||||
|
return file_offset + cur.r;
|
||||||
|
if(s.size() == 0)
|
||||||
|
return file_offset + cur.r;
|
||||||
|
|
||||||
return stoi(s);
|
return stoi(s);
|
||||||
}
|
}
|
||||||
// Taking user input - string
|
// Taking user input - string
|
||||||
|
|
Loading…
Reference in a new issue