关于结构体的引用问题?
#include<stdio.h>struct Product
{
char cName;
char cShape;
char cColor;
int iPrice;
char cArea;
};
int main()
{
struct Product product1;
printf("please enter product's name\n");
product1.cName="lcebox";
printf("please enter product's price\n");
product1.iPrice=2000;
printf("Name: %s\n",product1.cName);
printf("Price: %d\n",product1.iPrice);
return 0;
}
请问各位大神,以上程序单独输出product1.ipice时可以执行成功,为什么加上了 product1.cName语句时就报错了呢?? 17行使用strcpy试试。 #include <stdio.h>
struct Product
{
char cName;
char cShape;
char cColor;
int iPrice;
char cArea;
};
int main()
{
struct Product product1;
printf("please enter product's name\n");
scanf("%s", product1.cName); //叫人输入,却自己赋值……
printf("please enter product's price\n");
scanf("%d", &product1.iPrice);
printf("Name: %s\n", product1.cName);
printf("Price: %d\n", product1.iPrice);
return 0;
}
#include<stdio.h>
int main(){
char a;
a="你的问题是这个,字符串不能直接用=赋值,用函数去实现strcpy()"
return 0;
}
原型声明:char *strcpy(char* dest, const char *src);
头文件:#include <string.h> product1.cName是数组,数组输出能直接使用printf吗,要用下标才能输出数组
页:
[1]