获取错误C2440 #包括 #包括 结构学生 { char StudentName[50]; char学生专业[4]; 双学生GPA; 双学分制; char-StudentID[9]; }; void main() { 结构学生; strcpy(Student.StudentName,“Christian Gigliotti”); strcpy(学生,学生专业,“技术”); strcpy(Student.StudentGPA,“2.4”); strcpy(Student.StudentCredits,“31”); strcpy(Student.StudentID,“J02062414”); printf(“学生姓名:%s\n”,Student.StudentName); printf(“学生的专业:%s\n”,Student.StudentMajor); printf(“学生的平均成绩:%d\n”,Student.StudentGPA); printf(“学生获得的学分:%d\n”,Student.StudentCredits); printf(“学生ID:%s\n”,Student.StudentID); 返回0; }
我收到获取错误C2440 #包括 #包括 结构学生 { char StudentName[50]; char学生专业[4]; 双学生GPA; 双学分制; char-StudentID[9]; }; void main() { 结构学生; strcpy(Student.StudentName,“Christian Gigliotti”); strcpy(学生,学生专业,“技术”); strcpy(Student.StudentGPA,“2.4”); strcpy(Student.StudentCredits,“31”); strcpy(Student.StudentID,“J02062414”); printf(“学生姓名:%s\n”,Student.StudentName); printf(“学生的专业:%s\n”,Student.StudentMajor); printf(“学生的平均成绩:%d\n”,Student.StudentGPA); printf(“学生获得的学分:%d\n”,Student.StudentCredits); printf(“学生ID:%s\n”,Student.StudentID); 返回0; },c,compiler-errors,C,Compiler Errors,我收到错误C2440:“函数”:无法在第24行和第25行从“double”转换为“char*” 我想这与我试图用双倍的平均成绩和学分有关。我不明白为什么它会影响那些台词 您不能使用: #include <stdio.h> #include <string.h> struct student { char StudentName[50]; char StudentMajor[4]; double StudentGPA; double StudentCredits; cha
错误C2440:“函数”:无法在第24行和第25行从“double”转换为“char*”
我想这与我试图用双倍的平均成绩和学分有关。我不明白为什么它会影响那些台词 您不能使用:
#include <stdio.h>
#include <string.h>
struct student
{
char StudentName[50];
char StudentMajor[4];
double StudentGPA;
double StudentCredits;
char StudentID[9];
};
void main()
{
struct student Student;
strcpy(Student.StudentName, "Christian Gigliotti");
strcpy(Student.StudentMajor, "TECH");
strcpy(Student.StudentGPA, "2.4");
strcpy(Student.StudentCredits, "31");
strcpy(Student.StudentID, "J02062414");
printf("Student's Name: %s\n", Student.StudentName);
printf("Student's Major: %s\n", Student.StudentMajor);
printf("Student's GPA: %d\n", Student.StudentGPA);
printf("Student's Credits Earned: %d\n", Student.StudentCredits);
printf("Student's ID: %s\n", Student.StudentID);
return 0;
}
由于Student.StudentGPA
和Student.StudentCredits
属于double
类型
使用:
顺便说一句,电话线
Student.StudentGPA = 2.4;
Student.StudentCredits = 31;
将导致未定义的行为,因为Student.StudentMajor
没有足够的空间容纳这些字符和终止的空字符。将Student.StudentMajor
的大小设置为至少5
strcpy(Student.StudentMajor, "TECH");
他也有同样的问题。将Student.StudentID的大小设置为至少10。看起来您正试图在双人床上使用strcpy。
strcpy(Student.StudentMajor, "TECH");
strcpy(Student.StudentID, "J02062414");