数组类型char []不可转让 [英] Array type char[] is not assignable

查看:3225
本文介绍了数组类型char []不可转让的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

那么这里是我的第一篇文章。我一直在试图做这样的选择选择的事情,我希望用户选择,而不是打字下来只有数字(容易),但是当我想的数字等于一个字符串,它说:数组类型 CHAR [30] 是不可转让。即使在后面我把分号或没有。

 的#include<&stdio.h中GT;诠释主(){
  INT choice1;
  CHAR字[30];  的printf(你有三个选择\\ n);
  的printf([1]跳转[2]运行[3]舞\\ n);
  scanf函数(%d个,&安培; choice1);
  如果(choice1 == 1)
  {
    字=跳转//错误#1
  }
  否则如果(choice1 == 2)
  {
    字=吃//错误#2
  }
  否则,如果(choice1 == 3)
  {
    字=睡眠; //错误#3
  }  的printf(你现在会唱%字);}


解决方案

您不能的分配的一个数组,仅复制的吧。

使用 的strcpy 代替,像

 的strcpy(文字,跳);

Well here is my first post. I've been trying to do this choice choosing thing and I want the user to choose only numbers instead of typing them down (easier) but when I want the numbers to equal a string, it says "array type char[30] is not assignable". Even if at the back I put semi-colon or not.

#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);

}

解决方案

You can't assign to an array, only copy to it.

Use strcpy instead, like

strcpy(word, "Jump");

这篇关于数组类型char []不可转让的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆