利用指针给一个字符串数组赋值,怎么做?
#include<iostream>using namespace std;
struct CandyBar{
char name[20];
double weight;
int caloric;
};
CandyBar CandyFun(CandyBar &Candy,char *pName ="Millennium Munch",
double fWeight = 2.85,int fcaloric = 350);
int main(){
CandyBar myCandyBar;
cout <<"Enter the Candy's name:" ;
char pn[20];
cin.get(pn,20).get();
cout << "Enter the Candy's weight:";
double weight;
cin >> weight;
cout << "Enter the Candy's caloric:";
int caloric;
cin >> caloric;
CandyFun(myCandyBar,pn,weight,caloric);
}
CandyBar CandyFun(CandyBar &Candy,char* pName,double fWeight,int fcaloric){
Candy.name = *pName;
Candy.weight = fWeight;
Candy.caloric = fcaloric;
return Candy;
}
这是源代码,运行错误29 incompatible types in assignment of `char' to `char[20]' 位于 CandyFun函数的第一行?
...全文
相关推荐
C语言指针
很全面的介绍C语言指针 很全面的介绍C语言指针 很全面的介绍C语言指针
C数组和指针(学C必看)
学C语言必看的三本葵花宝典之一,高手从这里开始。欢迎从我这下载另两个宝典。。。
结构体中数组成员赋值
用实例教你给结构体中数组成员赋值
c代码-9、有5个字符串,首先将它们按照字符串中的字符个数由小到大排列, 再分别取出每个字符串的第三个字母合并成一个新的字符串输出(若少于三个字符的输出空格)。要求:利用字符串指针和指针数组实现。
c代码-9、有5个字符串,首先将它们按照字符串中的字符个数由小到大排列, 再分别取出每个字符串的第三个字母合并成一个新的字符串输出(若少于三个字符的输出空格)。要求:利用字符串指针和指针数组实现。
用指针数组的方法将字符串排序
用指针数组的方法将字符串排序



