-
Notifications
You must be signed in to change notification settings - Fork 1
/
impsas.c
155 lines (124 loc) · 3.15 KB
/
impsas.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <stdio.h>
#include <conio.h>
#include <process.h>
// Student strucure
typedef struct Student
{
char name[20];
int rollno;
char attend;
} Student;
Student student[100];
// shows all Attendance system options
void ShowOptions();
int main()
{
FILE *file;
int option, strength, dd, mm, yy;
char ch, c;
int i;
// use a while loop
while (1)
{
// clear screen
// clrscr();
// show options
ShowOptions();
scanf("%d",&option);
if (option == 1)
{
printf("ENTER THE CLASS STRENGTH:");
scanf("%d",&strength);
// open the file, write mode
// Student.txt stores data of students
file = fopen("Student.txt","w");
// check for error
if (!file)
{
printf("Error: Could not open Student.txt");
return 1; // error code 1
}
for( i=0; i<strength; i++)
{
printf("Enter %d Student Name:", i+1);
// get name including space within
scanf("%c");
scanf("%s", &student[i].name);
printf("ENTER ITS ROLL NO:");
scanf("%d",&student[i].rollno);
// store in the file
fprintf(file, "Roll No: %d\tName: %s\n", student[i].rollno, student[i].name);
}
// close the file
fclose(file);
}
else if (option == 2)
{
printf("\n\t\t\tTAKING ATTENDANCE");
printf("\t\tPRESS ENTER WHEN READY!!!");
printf("\tDATE(DD/MM/YY):");
scanf("%d/%d/%d", &dd, &mm, &yy);
scanf("%c");
// open file
// Attendance.txt stores attendance of students
file = fopen("Attendance.txt", "a");
// check for error
if(!file)
{
printf("Error: Could not open Attendance.txt");
return 1; // error code 1
}
fprintf(file, "ATTENDANCE ON %d-%d-%d\n", dd, mm, yy);
for( i=0; i<strength; i++)
{
printf("\nRoll no: %d \t\t Name:%s ", student[i].rollno, student[i].name);
printf("\n\nEnter attendance status for %s(P or A):", student[i].name);
scanf("%c", &student[i].attend);
scanf("%c");
// write to the file
fprintf(file,"\nAttendance: %c Roll no: %d Name: %s\n", student[i].attend, student[i].rollno, student[i].name);
}
// close file
fclose(file);
}
else if (option == 3)
{
file = fopen("Attendance.txt", "r");
// check for error
if(!file)
{
printf("Error: Could not open Attendance.txt");
return 1; // error code 1
}
// print character by character
ch=fgetc(file);
while(ch!=EOF)
{
printf("%c", ch);
ch=fgetc(file);
}
getch();
// close file
fclose(file);
}
else if (option == 4)
{
break;
}
else
{
printf("INVALID SELECTION!!!");
}
}
// successful termination
return 0;
}
void ShowOptions()
{
printf("\n\n\n\n\n STUDENT ATTENDANCE SYSTEM\n\n");
printf(" * PRESS 3 TO VIEW PREVIOUS ATTENDANCE IF HAD TAKEN\n");
printf(" * PRESS 1 FOR GIVING INPUT\n");
printf(" * PRESS 2 FOR TAKING ATTENDANCE\n");
printf(" * PRESS 4 FOR EXIT\n");
printf(" \n\n\t\t :");
}