最近在学习c语言,有好多问题都不懂啊。然后在结构体又出问题了
在下面的代码中,编译过程中总是提示name, species, teeth, age这四个标识符未定义,但是在前面的结构体中不是已经定义了吗。这个该怎么办啊,小的实在想不出来啦。
struct fish {
const char *name;
const char *species;
int teeth;
int age;
} ;
void catalog(struct fish f)
{
printf(“%s is a %s with %i teeth. He is %i.\n”, name, species, teeth, age);
}
void label(struct fish f)
{
printf(“Name: %s\nSpecies: %s\n%i years old,\n%i teeth\n”, name, species, teeth, age);
}
struct fish {
const char *name;
const char *species;
int teeth;
int age;
} ;
int main()
{
struct fish snappy = {“Snappy”, “Piraha”, 69, 4};
catalog(snappy);
label(snappy);
return 0;
}
在下面的代码中,编译过程中总是提示name, species, teeth, age这四个标识符未定义,但是在前面的结构体中不是已经定义了吗。这个该怎么办啊,小的实在想不出来啦。
struct fish {
const char *name;
const char *species;
int teeth;
int age;
} ;
void catalog(struct fish f)
{
printf(“%s is a %s with %i teeth. He is %i.\n”, name, species, teeth, age);
}
void label(struct fish f)
{
printf(“Name: %s\nSpecies: %s\n%i years old,\n%i teeth\n”, name, species, teeth, age);
}
struct fish {
const char *name;
const char *species;
int teeth;
int age;
} ;
int main()
{
struct fish snappy = {“Snappy”, “Piraha”, 69, 4};
catalog(snappy);
label(snappy);
return 0;
}
解决方案
20
void catalog(struct fish f)
{
printf(“%s is a %s with %i teeth. He is %i.\n”, f,name, f.species, f.teeth, f.age);
}
其余的相似
{
printf(“%s is a %s with %i teeth. He is %i.\n”, f,name, f.species, f.teeth, f.age);
}
其余的相似
40
#include<stdio.h> struct fish { const char *name; const char *species; int teeth; int age; } ; void catalog(struct fish f) { printf("%s is a %s with %i teeth. He is %i.\n", f.name, f.species, f.teeth, f.age); } void label(struct fish f) { printf("Name: %s\nSpecies: %s\n%i years old,\n%i teeth\n", f.name, f.species, f.teeth, f.age); } int main() { struct fish snappy = {"Snappy", "Piraha", 69, 4}; catalog(snappy); label(snappy); return 0; }