left operand must be l-value

--  作者:maimarco
--  發佈時間:2004-11-10 19:51:01

--  錯了嗎?不明白!!!!
// sd.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>

struct classd
{
char name[8];
int age;
};

int main(int argc, char* argv[])
{
char bb[8];
     classd class1;
       printf("%s/n","請輸入你的姓名:");
       scanf("%s",&bb);
     class1.name=bb;      //錯誤信息 "'=' : left operand must be l-value" 什麼原因

     
return 0;
}


--  作者:nearwate
--  發佈時間:2004-11-10 21:23:59

--  
因爲classd不是系統默認的數據類型,
所以不能像普通char類型那樣用=賦值,
只能用strcpy函數,
class1.name=bb;
應改爲:
strcpy(class1.name,bb);
但要在程序頭加上一個頭文件
#include <string.h>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章