Есть функция:
// Добавить n байт слов
struct output* WordList_Add_Word_S(unsigned long long int ByteLimit, struct wordlist* WordList){
// Переменные
bool exitkey = false; // Выйти из цикла
char tmpword[257]; // Временный контейнер для слова
char tmpchar; // Временный контейнер для символа
unsigned long int pos; // Текущая позиция
struct output * SpaceList = (struct output*)malloc(sizeof(struct output)); // Спэйс лист
// Начальная инициализация
pos = 0;
SpaceList->Spaces = (unsigned long *)malloc(sizeof(unsigned long));
SpaceList->Spaces[0] = 0;
SpaceList->RichEnd = false;
// Запуск цикла
while (exitkey != true){
// Считывание символа
if (scanf("%c", &tmpchar) == 0) {
// Ввод закончился
SpaceList->RichEnd = true;
tmpword[pos] = 0;
if (pos != 0) WordList_Add_Word(tmpword, WordList);
exitkey = true;
} else if ((tmpchar >= '0')&&(tmpchar <= 'Z')) {
// Если буква
tmpword[pos] = tolower(tmpchar);
pos++;
} else if ((tmpchar < '0')&&(tmpchar != '\n')&&(tmpchar != '$')&&(pos > 0)) {
// Если пробел
tmpword[pos] = 0;
ByteLimit = ByteLimit - (pos+1);
pos = 0;
WordList_Add_Word(tmpword, WordList);
} else if (tmpchar == '\n') {
// Если переход на новую строку
// Добавляем инфу о строке
SpaceList->Spaces[0]++;
SpaceList->Spaces = (unsigned long int*)realloc(SpaceList->Spaces, (SpaceList->Spaces[0]+1)*sizeof(unsigned long int));
SpaceList->Spaces[SpaceList->Spaces[0]] = WordList->Count;
// Если у нас в буфере еще лежит слово
if (pos > 0) {
tmpword[pos] = 0;
ByteLimit = ByteLimit - (pos+1);
pos = 0;
WordList_Add_Word(tmpword, WordList);
}
} else if (tmpchar == '$') exitkey = true;
// Ограничитель на размер памяти
if ((ByteLimit <= 257)&&(pos == 0)) exitkey = true;
}
Я подаю на ввод 'w', тут условие не выполняется:
if (scanf("%c", &tmpchar) == 0) {
НО! После вместо того, чтобы пройти условие:
} else if ((tmpchar >= '0')&&(tmpchar <= 'Z'))
Программа резко улетает сразу вниз, к:
if ((ByteLimit <= 257)&&(pos == 0)) exitkey = true;
Не совсем понимаю - почему так и как исправить?
Можете помочь?
tmpchar
? Может, там с предыдущего ввода\n
в буфере сидит?...