Определить, являются ли буквы в строке упорядоченными по алфавиту - C (СИ)
Формулировка задачи:
Ввести строку, состоящую только из букв, и определить, являются ли буквы в строке упорядоченными по алфавиту.
сразу же после ввода строки ошибку выдает
#include <stdio.h>
#include <string.h>
#include<stdlib.h>
void main()
{
char str[80];
int i;
puts("Vvedite stroku");
scanf("%s",str);
if(str[i]>='Г*' && str[i]<='Гї' || str[i]>='ГЂ' && str[i]<='Гџ')
{
printf("Bukvi uporyadocheni po alfavitu");
}
else
{
printf("Bukvi ne uporyadocheni po alfavitu");
}
getchar();
}Решение задачи: «Определить, являются ли буквы в строке упорядоченными по алфавиту»
textual
Листинг программы
#include <iostream>
#include <ctype.h>
using namespace std;
bool str_abc(const char* str) {
const char* iter = str;
while( *iter ) {
for(const char* p = str; p != iter; *p++) {
if( toupper(*p) > toupper(*iter))
return false;
}
*iter++;
}
return true;
}
int main(void)
{
char str[32];
int cycle = 10;
while(cycle--) {
scanf("%s", str);
if(str_abc(str))
cout << "\t*string ASC*" << endl;
else
cout << " - no string abc !" << endl;
}
cin.get();
return 0;
}