小编Sky*_*der的帖子

数组类型char []不可分配

那么这是我的第一篇文章.我一直在尝试做这个选择选择的东西,我希望用户只选择数字而不是键入它们(更容易)但是当我希望数字等于一个字符串时,它说"数组类型char[30]不可分配".即使在后面我也放了分号.

#include <stdio.h>

int main() {
  int choice1;
  char word[30];

  printf("You have three choice.\n");
  printf("[1] Jump [2] Run [3] Dance\n");
  scanf("%d",&choice1);
  if (choice1 == 1)
  {
    word = "Jump" //Error #1
  }
  else if (choice1 == 2)
  {
    word = "Eat" //Error #2
  }
  else if (choice1 == 3)
  {
    word = "Sleep"; //Error #3
  }

  printf("You will now be %sing",word);

}
Run Code Online (Sandbox Code Playgroud)

c arrays string assignment-operator

21
推荐指数
4
解决办法
5万
查看次数

标签 统计

arrays ×1

assignment-operator ×1

c ×1

string ×1