Hello
If i have a char name[40], in my struct, how would I be able to read in a value for the name, and then apply it to the struct, for the char name[] ?
Thanks
Hello
If i have a char name[40], in my struct, how would I be able to read in a value for the name, and then apply it to the struct, for the char name[] ?
Thanks
U want to know how to read a string value into a struct variables member??
simple
struct <whatever> <var>
scanf("%s",var.name);
Is that what u were looking for?
Regards,
Sriharsha.
Help everyone you can
main()
{
typedef struct {
int year;
char make[40];
char colour[40];
float price;
} car;
car number1;
I would like to ask them for the make of the car, and put it into the make var(above).
Thanks
printf("Enter make of car > ");
gets(car->make);
I hope this is what you're looking for.. let me know... Looking at it now, I'm not sure what the name of your structure is.. try it anyhow(??), if you want...
>printf("Enter make of car > ");
>gets(car->make);
A tiny Correction...
gets(number1.make);
B'Cos, car is not a structure variable and neither number1 is declared as a pointer....(so u cant use the -> operator).
Regards,
Sriharsha
Help everyone you can
A big Correction...A tiny Correction...
gets(number1.make);
Why give the user the opportunity to overwrite memory not assigned for them
check your docs for fgets()Code:fgets( number1.make, sizeof( number1.make ), stdin );
Last edited by C_Coder; 04-16-2002 at 01:39 PM.
All spelling mistakes, syntatical errors and stupid comments are intentional.