【问题标题】:Confusing of "Access Violation "混淆“访问冲突”
【发布时间】:2014-03-10 17:13:29
【问题描述】:

我不明白这个案例,但这对我来说真的很重要,请帮助我......

void __fastcall TForm1::Button4Click(TObject *Sender)
{
    String masuk, keluar, kosong;
    int i, x, j, n = 0;

    masuk = Edit2->Text;
    keluar = masuk;
    kosong = " ";
    n = 0;
    x = 0;

mulai:
    i = 1;
    j = 0;
    j = j + n;
    i = i + j;
    if (masuk[i] == 'a')
    {
        keluar[i] = 't';
    }
    else if (masuk[i] == 't')
    {
        keluar[i] = 'a';
    }
    else if (masuk[i] == 'c')
    {
        keluar[i] = 'g';
    }
    else if (masuk[i] == 'g')
    {
        keluar[i] = 'c';
    }
    else
    {
        Application->MessageBoxA("Masukan Anda Salah", "Peringatan", MB_OK | MB_ICONWARNING);
        keluar = kosong;
        goto end;
    }
    n = n + 1;
    if (i < 10)
        goto mulai;
    else
        goto end;

end:
    Memo1->Text = keluar;
}

如果我让 masukan 超过 10(i

【问题讨论】:

  • 为什么使用gotos 而不是正确的循环?
  • 访问冲突通常意味着您尝试访问当前内存块不可用的内存,即您超出了数组(字符串)的范围。另外,不要使用 goto。
  • 看起来与 DNA/RNA 相关。我假设 a,t,g,c 是腺苷、鸟嘌呤、胸腺嘧啶和胞嘧啶。
  • 如果有人想知道变量名称的语言似乎是印度尼西亚语。
  • 我曾经尝试过这种方式,但我的程序无法读取循环。当我输入 for (int i=0; i

标签: c++ c++builder


【解决方案1】:

在黑暗中拍摄,但我认为你真正想要做的可能是这个。我假设您正在获取一个包含 10 个字符的字符串,它代表基因组的一半,并且您正在生成另一个字符串对值。

void __fastcall TForm1::Button4Click(TObject *Sender)
{
  String masuk, keluar;
  masuk = Edit2->Text;
  keluar = masuk;

  char kosong = ' ';

  for (int i=0; i < 10; i++)
  {
    switch(masuk[i]) {
      case 'a':
        keluar[i] = 't';
        break;
      case 't':
        keluar[i] = 'a';
        break;
      case 'c':
        keluar[i] = 'g';
        break;
      case 'g':
        keluar[i] = 'c';
        break;
      default:
        Application->MessageBoxA("Masukan Anda Salah", "Peringatan", MB_OK | MB_ICONWARNING);
        keluar[i] = kosong;
        break;
  }
  Memo1->Text = keluar;
}

【讨论】:

  • 我曾经尝试过这种方式,但我的程序无法读取循环。当我输入 for (int i=0; i
猜你喜欢
  • 1970-01-01
  • 2020-04-29
  • 2023-04-03
  • 1970-01-01
  • 2018-06-14
  • 2013-04-30
  • 2017-05-06
  • 2013-02-26
相关资源
最近更新 更多