Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
C-Assignment
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mohamed Yasar arafath K M
C-Assignment
Commits
20515a23
Commit
20515a23
authored
2 years ago
by
Mohamed Yasar arafath K M
Browse files
Options
Downloads
Patches
Plain Diff
initial commit
parent
ce8cb76f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
filetemplate.c
+74
-7
74 additions, 7 deletions
filetemplate.c
filetemplate.txt
+2
-2
2 additions, 2 deletions
filetemplate.txt
with
76 additions
and
9 deletions
filetemplate.c
+
74
−
7
View file @
20515a23
#include
<stdio.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
#include
<string.h>
struct
data
struct
data
{
{
int
register_no
;
int
register_no
;
char
name
[
10
];
char
name
[
10
];
char
department
[
10
];
char
department
[
10
];
float
avg
;
float
average
;
}
save
[
5
];
}
save
[
4
];
//Struct variable declaration
int
i
;
// declare a global variable
int
Department_name
();
// function declaration
int
main
()
int
main
()
{
{
int
i
;
int
no_rec
;
//Storing a No.of record
FILE
*
fp
=
fopen
(
"filetemplate.txt"
,
"r"
);
char
ch
;
// character to print the file char by char
while
(
fscanf
(
fp
,
"%d %s %s %f"
,
&
save
->
register_no
,
save
->
name
,
save
->
department
,
&
save
->
avg
)
!=
EOF
)
FILE
*
fp
=
fopen
(
"filetemplate.txt"
,
"r+"
);
//Open the file with reading and write
while
(
fp
!=
NULL
)
{
ch
=
fgetc
(
fp
);
if
(
ch
!=
EOF
)
{
printf
(
"%c"
,
ch
);
}
else
break
;
}
printf
(
"%s"
,
"
\n\n
"
);
rewind
(
fp
);
// fseek(fp,SEEK_SET,0);
fscanf
(
fp
,
"%d"
,
&
no_rec
);
for
(
i
=
1
;
i
<=
4
;
i
++
)
{
{
printf
(
"%s
\n
"
,
save
->
name
);
fscanf
(
fp
,
"%d %s %s %f
"
,
&
save
[
i
].
register_no
,
save
[
i
].
name
,
save
[
i
].
department
,
&
save
[
i
].
average
);
}
}
printf
(
"%s"
,
save
->
department
);
Department_name
(
save
,
no_rec
);
fclose
(
fp
);
return
0
;
return
0
;
}
}
int
Department_name
(
struct
data
*
save
,
int
no_rec
)
{
char
inp
[
3
];
int
CSE_count
=
0
,
IT_count
=
0
,
avg
=
0
,
avg2
=
0
;
for
(
i
=
1
;
i
<=
no_rec
;
i
++
)
//count and store the data in the count variable
{
if
(
!
(
strcmp
(
save
[
i
].
department
,
"CSE"
)))
{
CSE_count
+=
1
;
}
else
if
(
!
(
strcmp
(
save
[
i
].
department
,
"IT"
)))
{
IT_count
+=
1
;
}
}
printf
(
"CSE Department records : %d
\n
"
,
CSE_count
);
//print the CSE department data separately
for
(
i
=
1
;
i
<=
4
;
i
++
)
{
if
(
!
(
strcmp
(
save
[
i
].
department
,
"CSE"
)))
// conditional check to find out CSE or Not
{
printf
(
"%d
\t
%s
\t
%s
\t
%.2f
\n
"
,
save
[
i
].
register_no
,
save
[
i
].
name
,
save
[
i
].
department
,
save
[
i
].
average
);
}
}
printf
(
"IT Department records : %d
\n
"
,
IT_count
);
//print the IT department data separately
for
(
i
=
1
;
i
<=
4
;
i
++
)
{
if
(
!
(
strcmp
(
save
[
i
].
department
,
"IT"
)))
// conditional check to find out CSE or Not
{
printf
(
"%d
\t
%s
\t
%s
\t
%.2f
\n
"
,
save
[
i
].
register_no
,
save
[
i
].
name
,
save
[
i
].
department
,
save
[
i
].
average
);
}
}
printf
(
"Enter the department name :"
);
scanf
(
"%s"
,
inp
);
for
(
i
=
1
;
i
<=
4
;
i
++
)
{
if
(
!
(
strcmp
(
inp
,
save
[
i
].
department
)))
{
if
(
avg
<
save
[
i
].
average
)
{
avg
=
save
[
i
].
average
;
avg2
=
i
;
}
}
}
printf
(
"High Avg Scored by
\n
"
);
printf
(
"%d
\t
%s
\t
%s
\t
%.2f
\n
"
,
save
[
avg2
].
register_no
,
save
[
avg2
].
name
,
save
[
avg2
].
department
,
save
[
avg2
].
average
);
}
This diff is collapsed.
Click to expand it.
filetemplate.txt
+
2
−
2
View file @
20515a23
Noofrecords 4
4
1001 raj CSE 76.5
1001 raj CSE 76.5
1002 raja IT 80.2
1002 raja IT 80.2
1003 kumar CSE 90.2
1003 kumar CSE 90.2
1004 siva IT 65.8
1004 siva IT 65.8
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment