G
G
greetrays_kap2020-06-01 18:35:55
C++ / C#
greetrays_kap, 2020-06-01 18:35:55

How to output Russian letters (SI) normally?

I started writing a program to find palindromes. The text is pre-processed, from which I remove all punctuation marks and spaces (except for periods). I got to the string comparison algorithm, and, it would seem, everything should work, but the command line gives the following:

avenisesineva
veniеeЁѸneva
no

alamamal
Ѱlamamala
no

The first line is the palindrome itself.
The second line is a palindrome, which I wrote to the array in the opposite direction for subsequent checking for similarity.
Third line - Output whether the given sentences are palindromes.

The question is, why are these "hieroglyphs" written in the second line? It seems like he connected the Russian language to the code, but it seems that this is not the case.

The code of the algorithm itself:

#include "palindrom.h"
#include <stdio.h>
#include <locale.h>
#include <string.h>

int search_pal (char *prop, int count){
  setlocale(LC_ALL, "Rus");
  int i, j = 0;
  char prop2[count];
  count = count - 1;
  for (i = count; i >= 0; i--){
    prop2[j] = prop[i];
    j++;
  }
  puts(prop);
  puts(prop2);
  if(strcmp(prop,prop2)==0)
    puts("да\n");
  else
    puts("нет\n");
printf("\n");
}


main function code:
#include "palindrom.h"
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#define CONST 100000

int main(int argc, char* argv[])
{
    int size = 0;
    setlocale(LC_ALL, "Rus"); //подключаем русский язык
    char* text = NULL; //создаём указатель на массив
    text = (char*)malloc(CONST * sizeof(int)); //выделяем память под константу
    FILE* text_file;
    text_file = fopen(argv[1], "r"); //открываем файл для чтения
    if (text_file != NULL) { //идёт проверка на NULL
        while (fgets(text, CONST, text_file)) { // получаем данные из файла
        }
    } else {
        printf("Ошибка: Аргумент не найден.\n ");
    }
    for (int i = 0; text[i] != '\0'; i++){ //подсчёт размера в строке
      size++;
    }
    text = realloc(text, size * sizeof(int)); //перераспределям память под размер
    printf ("Ваш текст:\n\n"); //вывод текста пользователя на экран
    for (int i = 0; i < size; i++) {
        printf("%c", text[i]);
    }
    breaking_up(text, size); //эта функция избавляет текст от символов и пробелов, 
    return 0;                       //из неё вызывается функция выше
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2020-06-01
@greetrays_kap

It could work on 8-bit encodings, but you probably have UTF-8.
In it, Russian letters occupy 2 bytes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question