-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathstructToFunctionByPointer.c
35 lines (32 loc) · 1.02 KB
/
structToFunctionByPointer.c
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
#include <stdio.h>
struct student{
char firstName[30];
char lastName[30];
int birthYear;
double aveGrade;
};
void printStudent(struct student);
void readStudent(struct student *studptr);
int main(void) {
//! showMemory(start=65520)
struct student me;
readStudent(&me);
printStudent(me);
return 0;
}
void readStudent(struct student *studptr) {
printf("\nEnter a new student record: \n");
printf("First name: ");
scanf("%s", (*studptr).firstName); // equivalent to scanf("%s", studptr->firstname)
printf("Last name: ");
scanf("%s", (*studptr).lastName); //scanf("%s", studptr->lastname)
printf("Birth year: ");
scanf("%d", &(*studptr).birthYear); // scanf("%d", &studptr->birthYear)
printf("Average grade: ");
scanf("%lf", &(*studptr).aveGrade); // scanf("%d", &studptr->aveGrade)
}
void printStudent(struct student stud) {
printf("Name: %s %s\n", stud.firstName, stud.lastName);
printf("Year of birth: %d\n",stud.birthYear);
printf("Average grade: %.2lf\n",stud.aveGrade);
}