phyte
12-20-2002, 01:45 PM
//structures
#include <stdio.h>
struct cars{
int year;
char model[15];
int engine_power;
float weight;
};
int main(){
struct cars van;
van.year=1998;
//gets(van.model);
van.model="TOYOTA";
van.engine_power=500;
van.weight=34.3;
printf("Year:%d\tModel:%s\tCC:%d\tWeight:%f\n",van.year,van.model,van.engine_power,van.weight);
return 0;
}
I get an error when i compile my code...Theres a snippet above..
The error is:
structs.c: In function `main':
structs.c:16: incompatible types in assignment
Why can't i initialize the van.model value this way?
If i use something like gets..It works fine...
Thanks in advance for your help..
#include <stdio.h>
struct cars{
int year;
char model[15];
int engine_power;
float weight;
};
int main(){
struct cars van;
van.year=1998;
//gets(van.model);
van.model="TOYOTA";
van.engine_power=500;
van.weight=34.3;
printf("Year:%d\tModel:%s\tCC:%d\tWeight:%f\n",van.year,van.model,van.engine_power,van.weight);
return 0;
}
I get an error when i compile my code...Theres a snippet above..
The error is:
structs.c: In function `main':
structs.c:16: incompatible types in assignment
Why can't i initialize the van.model value this way?
If i use something like gets..It works fine...
Thanks in advance for your help..