|
From: <and...@su...> - 2003-04-11 19:18:37
|
Please! Foget the auto name!!!! It´s a keyword. Chage it for some like
hot_auto :-)))))
Andre
-----Mensagem original-----
De: André Macário Barros [mailto:and...@su...]
Enviada em: sexta-feira, 11 de abril de 2003 16:09
Para: Dev-Cpp-Users
Assunto: structs
Please consider the following code:
1 -#include <stdio.h>
2 -#include <stdlib.h>
3 -
4 -struct car
5 -{
6 - int size;
7 - char name[10];
8 -};
9 -
10-int elevator(struct car);
11-
12-int main()
13-{
14- int floor;
15- struct car auto;
16-
17- printf("Enter car name-->");
18- gets(auto.name);
19- printf("Enter car size-->");
20- scanf("%d", &auto.size);
21- floor = elevator(auto);
22- printf("Please park your %s in the %d. floor\n", auto.name, floor);
23- system("PAUSE");
24- return 0;
25-}
26-
27-int elevator(struct car car_arg)
28-{
29- if(car_arg.size == 1) return 1;
30- if(car_arg.size == 2) return 2;
31- if(car_arg.size == 3) return 3;
32-}
1-I know that I don´t need to pass all the struct. Only the size is enough;
:-)))
2-I know I don´t need the int floor variable. I could directly call the
elevator function as
argument in line 22 printf; :-)))
3-I am calling the lines 4 until 8, as the "struct definition";
4-I am calling the line 15 and the argument function in line 27, as the
"struct variable
declarations";
My Questions:
A) My statement in 3 is correct?(y/n, comment)
B) My statement in 4 is correct?(y/n, comment)
C) Is there any way to rewrite this code to avoid a global "struct
definition"? That is, how
could I eliminate the lines 4 to 8, put them inside main and inside
elevator functions?
Thank you again
Andre
|