C语言执行时报错“表达式必须是可修改的左值,无法从“const char [3]”转换为“char [120]” ”,原因:字符串不能直接赋值
// testArray.cpp : 定义控制台应用程序的入口点。 #include "stdafx.h"
#include "string.h" #define MAX_AGE_SIZE 120
#define MAX_NAME_SIZE 100 typedef enum{//枚举值定义
walking = ,
running = ,
swimming = ,
jumpping = ,
sleeping =
}Hobby; typedef enum{
Chinese = ,
English = ,
Japanese =
}Language; typedef struct People{//结构体定义
union{//联合体定义,使用方法和struct类似
struct{
char age[MAX_AGE_SIZE];
char name[MAX_NAME_SIZE];
}Child;
Hobby hobby;
Language language;
}Student;
}People; int _tmain(int argc, _TCHAR* argv[])
{
char name1[MAX_NAME_SIZE] = {"test1"};
char name2[MAX_NAME_SIZE] = {"test2"}; People p[];
//p[0].Student.Child.age = "10";//报错:表达式必须是可修改的左值(原因:字符串不能直接赋值 )
strcpy(p[].Student.Child.age,"");//使用strcpy函数实现字符串拷贝
strcpy(p[].Student.Child.name,name1);
p[].Student.hobby = walking;
p[].Student.language = Chinese; strcpy(p[].Student.Child.age,"");
strcpy(p[].Student.Child.name,name2);
p[].Student.hobby = running;
p[].Student.language = English; printf("Student1's name:%s\n",p[].Student.Child.name);
return ;
}
C语言执行时报错“表达式必须是可修改的左值,无法从“const char [3]”转换为“char [120]” ”,原因:字符串不能直接赋值的更多相关文章
- PyQt程序执行时报错:AttributeError: 'winTest' object has no attribute 'setCentralWidget'的解决方法
用QtDesigner设计了一个UI界面,保存在文件Ui_wintest.ui中,界面中使用了MainWindow窗口,窗口名字也叫MainWindow,用PyUIC将其转换成了 Ui_wintest ...
- 高版本 MySQL 导出的脚本到低版本 MySQL 中执行时报错
导入 MySQL 脚本时报错:[ERR] 1273 - Unknown collation: 'utf8mb4_0900_ai_ci'低版本还不支持 utfmb4 这个字符集 解决方法:将 sql 脚 ...
- mac Robotframework执行时报错Robot Framework installation not found.
虽然已经装了,但一直报错 ,版本是3.1.1 最新版 ➜ ~ pip install robotframework DEPRECATION: Python 2.7 will reach the en ...
- Android项目执行时报错NoclassDefFoundError
导Android项目时碰到个头疼的NoclassDefFoundError. 项目导入之后是没有报错的.可是执行就报这个错误 java.lang.NoClassDefFoundError: andro ...
- 问题:程序编译通过,但是执行时报错:coredump
问题描述: 在一个客户现场搭建环境时,遇到了一个棘手的问题,C代码编译通过后,无法正常运行,启动会出现“coredump”错误. 运行环境为新搭建的AIX6.1,数据库为Oracle11.2.0.2. ...
- jmeter通过ant执行时报错 jmeter.log not found
原因:权限执行不够,改为root用户即可 :sudo su 日志报错如下: test: [jmeter] Executing test plan: /home/ec2-user/jmeterProg ...
- pyinstaller打出的EXE包执行时报错“failed to excute ”信息
我的程序是selenium自动化脚本,打包时执行的是 Python pyinstaller -F --onefile -w XXX.py 这样打出的包执行后提示“failed to excute s ...
- sql server 作业导出放到另外一台机器执行时报错的解决方法
SQL Server2008脚本创建作业失败,提示: 引用内容消息 515,级别 16,状态 2,过程 sp_add_job,第 137 行不能将值 NULL 插入列 'owner_sid',表 'm ...
- 初始化mysql数据库 /usr/bin/mysql_install_db执行时报错
错误描述: FATAL ERROR: please install the following Perl modules before executing /usr/bin/mysql_install ...
随机推荐
- C# 线程通信 一
C#多线程通信 using System; using System.Collections.Generic; using System.Linq; using System.Text; using ...
- 面对对象之@classmethod、@staticmethod用法
@classmethod用法(修饰的函数,第一个参数cls默认是类名,调用方法:实例对象或类对象.方法) class C_mthod(object): name = "f**k" ...
- linux开启telnet
windows客户端如果通过cmd窗口连接到远程linux服务器,可以使用telnet: centos系统默认telnet 23端口是关闭的. 服务器本地使用nmap ip地址 -p 23 查看tel ...
- iOS的多版本配置(版本分离,多环境配置)
前几天公司说一个客户要搞一个app,我说搞呗,跟我啥关系...他说,就是从咱的app上搞,什么都一样,就是一些logo啥的不一样.我一开始感觉,那就改改logo呗,后来一想,凑,百度推送,友盟统计,B ...
- 轻松解决U盘中病毒,文件变成.exe执行文件的问题
U盘中的文件都变成.exe可执行文件是怎么回事?告诉你,你的U盘中病毒了,那么如何清除呢?小编现在就告诉你几个简单方法,轻松就能搞定U盘中病毒问题. 方法1: (1)首先使用杀毒软件把U盘杀杀毒,除去 ...
- 使用Spring AsyncRestTemplate对象进行异步请求调用
直接上代码: package com.mlxs.common.server.asyncrest; import org.apache.log4j.Logger; import org.springfr ...
- Codeforces Round #388 (Div. 2) A,B,C,D
A. Bachgold Problem time limit per test 1 second memory limit per test 256 megabytes input standard ...
- [转] - 在mac的终端中使用sublime打开文件
在mac的终端中使用sublime打开文件 使用sublime提供的命令行工具.这个命令行工具位于 /Applications/Sublime\ Text\ 2.app/Contents/Shared ...
- jsp发布:Could not publish server configuration: null. java.lang.NullPointerException
1.jsp发布: Could not publish server configuration: null. java.lang.NullPointerException
- PHP Mysqli 数据库连接
---恢复内容开始--- $connection=new mysqli($db_host,$db_user,$db_password,$db_name);if(!mysqli_connect_errn ...