S
S
sdenish2021-12-21 23:12:44
C++ / C#
sdenish, 2021-12-21 23:12:44

It is necessary to make a cyclic shift to the right by 8 positions. Read from file and write to file. What's wrong?

int main() {
  FILE* bb, * aa;
  int n, i, j;
  char str[100], c;
  fopen_s(&bb, "text1.txt", "w"); // Открываем файлы для чтения и для записи
  fopen_s(&aa, "text.txt", "r");
  printf("Vvedite kolichestvo simvolov\n");
  scanf_s("%d", &n);	
  c = fgetc(aa);
  i = 0;
  while (c != EOF) { // Заполняем массив символами
    str[i] = c;
    i++;
    c = fgetc(aa);
  }
  char t = str[0],x;
  for (int i = 0; i < 8; i++) {
    str[0] = str[n - 1];
    for (int j = 0; j < str[n]; j++) {
      x = str[j];
      str[j] = t;
      t = x;
    }
    fputc(str[i], bb);
  }
  fclose(bb); // Закрываем оба файла.
  fclose(aa);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2021-12-22
@res2001

The cyclic shift algorithm is described in John Bentley's old book "Gems of Programming".
https://codelib.ru/task/cycle_shift/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question