-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lecture21 Struct.c
69 lines (41 loc) · 1.06 KB
/
Lecture21 Struct.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
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
68
69
#include <stdio.h>
#include <stdlib.h>
//Written by Bunyamin Yavuz in 2022
//Struct
// Create a student struct
struct Student{
long int number;
int age;
char name[50];
int totalMarks;
}std;
int main()
{
/*
<-----Syntax of Struct in C----->
struct structureName {
dataType member1;
dataType member2;
...
}(alias);
*/
struct Student s1;
// Accessing members of the struct
s1.number = 200254018;
s1.age = 19;
char s[]="Bunyamin";
strcpy(s1.name,s);
s1.totalMarks = 499;
printf("Number: %d \nName: %s \nTotal Marks: %d\n",s1.number,s1.name,s1.totalMarks);
// Get from keyboard (Struct)
printf("Enter your university number :\n");
scanf("%d",&std.number);
printf("Enter your age :\n");
scanf("%d",&std.age);
printf("Write your name :\n");
scanf("%d",&std.name);
printf("Enter your total marks :\n");
scanf("%d",&std.totalMarks);
printf("Number: %d \nName: %s \nTotal Marks: %d",s1.number,s1.name,s1.totalMarks);
return 0;
}