-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathptrToStruct.c
More file actions
67 lines (51 loc) · 1.55 KB
/
ptrToStruct.c
File metadata and controls
67 lines (51 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
struct car {
int nbrOfTyres, nbrOfDoors, nbrOfSeats;
char color[20], model[100];
float price;
};
void sanitize(char *ptrToChar) {
char *source = ptrToChar;
char *destination = ptrToChar;
while (*source != '\0') {
if (*source != '\n' && *source != '\r') {
*destination = *source;
destination++;
}
source++;
}
*destination = '\0';
}
struct car Benz;
struct car *ptrToBenz = NULL;
void readInputsFor(struct car *ptr) {
printf("Input specifications for a car below\n------------------------------------\n\n");
printf("Input the number of \"tyres\"\n=>");
scanf("%d", &ptr->nbrOfTyres);
printf("Input number of \"Doors\" please\n=>");
scanf("%d", &ptr->nbrOfDoors);
printf("Input the number of \"Seats\" please\n=>");
scanf("%d", &ptr->nbrOfSeats);
getchar();
printf("Input the \"Color\" please\n=>");
fgets(ptr->color, sizeof(ptr->color), stdin);
sanitize(ptr->color);
printf("Input the \"Model\" please\n=>");
fgets(ptr->model, sizeof(ptr->model), stdin);
sanitize(ptr->model);
printf("\n---\nSuccessfully recorded: \n\"A %d wheel, %d door, %d seat %s %s\"\n---\n",
ptr->nbrOfTyres, ptr->nbrOfDoors, ptr->nbrOfSeats, ptr->color, ptr->model);
}
void print(struct car *ptr) {
printf("\nVehicle specifications for \"%s\" \n--------------\n", ptr->model);
printf("%d Wheels\n", ptr->nbrOfTyres);
printf("%d Seats\n", ptr->nbrOfSeats);
printf("%d Doors\n", ptr->nbrOfDoors);
printf("\"%s\" color\n", ptr->color);
}
int main() {
ptrToBenz = &Benz;
readInputsFor(ptrToBenz);
print(ptrToBenz);
return 0;
}