Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- long double my_input2() {
- long double data;
- int len = 0;
- char ch = getc(stdin);
- char* str = (char*)malloc(sizeof(char));
- char** endptr = nullptr; // переменная для strtod()
- bool yea = 1; // можем ввести символ или нет в цикле и удачное ли считывание в return
- while (ch != '\n') { // считываем строку
- if (ch == 48) {
- yea = 1;
- } else if (ch != ' ') {
- yea = 1;
- } else if (ch != 48) {
- yea = 0;
- }
- str[len] = ch;
- str = (char*)realloc(str,(1 + (++len)*sizeof(char)));
- ch = getc(stdin);
- }
- data = strtod(str, endptr);
- if (!data && !yea) {
- printf("Vvedite eshe raz:\n");
- return my_input2();
- } else {
- return data;
- }
- }
Add Comment
Please, Sign In to add comment