Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cs283
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
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Joey Le
Cs283
Commits
db5462f8
Commit
db5462f8
authored
7 months ago
by
Joey Le
Browse files
Options
Downloads
Patches
Plain Diff
"Finishd all of the functions "
parent
ad889bbc
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Assignmnt-02/starter/sdbsc.c
+92
-9
92 additions, 9 deletions
Assignmnt-02/starter/sdbsc.c
with
92 additions
and
9 deletions
Assignmnt-02/starter/sdbsc.c
+
92
−
9
View file @
db5462f8
...
@@ -204,7 +204,7 @@ int del_student(int fd, int id)
...
@@ -204,7 +204,7 @@ int del_student(int fd, int id)
myoffset
=
id
*
STUDENT_RECORD_SIZE
;
myoffset
=
id
*
STUDENT_RECORD_SIZE
;
off_t
lseek_result
=
lseek
(
fd
,
myoffset
,
SEEK_SET
);
off_t
lseek_result
=
lseek
(
fd
,
myoffset
,
SEEK_SET
);
if
(
lseek_result
)
{
if
(
lseek_result
<
1
)
{
printf
(
M_ERR_DB_READ
);
printf
(
M_ERR_DB_READ
);
return
ERR_DB_FILE
;
return
ERR_DB_FILE
;
}
}
...
@@ -246,9 +246,41 @@ int del_student(int fd, int id)
...
@@ -246,9 +246,41 @@ int del_student(int fd, int id)
*/
*/
int
count_db_records
(
int
fd
)
int
count_db_records
(
int
fd
)
{
{
// TODO
int
count
=
0
;
printf
(
M_NOT_IMPL
);
student_t
temp
;
return
NOT_IMPLEMENTED_YET
;
ssize_t
bytes
;
off_t
lseek_result
=
lseek
(
fd
,
0
,
SEEK_SET
);
if
(
lseek_result
<
0
)
{
printf
(
M_ERR_DB_READ
);
return
ERR_DB_FILE
;
}
while
(
1
)
{
bytes
=
read
(
fd
,
&
temp
,
sizeof
(
student_t
)
);
if
(
bytes
==
-
1
)
{
return
ERR_DB_FILE
;
}
else
if
(
bytes
==
0
)
{
break
;
}
else
if
(
bytes
!=
STUDENT_RECORD_SIZE
)
{
return
ERR_DB_FILE
;
}
if
(
memcmp
(
&
temp
,
&
EMPTY_STUDENT_RECORD
,
STUDENT_RECORD_SIZE
)
!=
0
)
{
count
++
;
}
}
if
(
count
==
0
){
printf
(
M_DB_EMPTY
);
}
else
{
printf
(
M_DB_RECORD_CNT
,
count
);
}
return
count
;
}
}
/*
/*
...
@@ -286,11 +318,53 @@ int count_db_records(int fd)
...
@@ -286,11 +318,53 @@ int count_db_records(int fd)
*/
*/
int
print_db
(
int
fd
)
int
print_db
(
int
fd
)
{
{
// TODO
student_t
temp
;
printf
(
M_NOT_IMPL
);
ssize_t
bytes
;
return
NOT_IMPLEMENTED_YET
;
int
first_record
=
1
;
off_t
lseek_result
=
lseek
(
fd
,
0
,
SEEK_SET
);
if
(
lseek_result
<
0
)
{
printf
(
M_ERR_DB_READ
);
return
ERR_DB_FILE
;
}
}
while
(
1
)
{
bytes
=
read
(
fd
,
&
temp
,
sizeof
(
student_t
)
);
if
(
bytes
==
-
1
)
{
printf
(
M_ERR_DB_READ
);
return
ERR_DB_FILE
;
}
else
if
(
bytes
==
0
)
{
break
;
}
else
if
(
bytes
!=
STUDENT_RECORD_SIZE
)
{
printf
(
M_ERR_DB_READ
);
return
ERR_DB_FILE
;
}
if
(
memcmp
(
&
temp
,
&
EMPTY_STUDENT_RECORD
,
STUDENT_RECORD_SIZE
)
==
0
)
{
continue
;
}
if
(
first_record
)
{
printf
(
STUDENT_PRINT_HDR_STRING
,
"ID"
,
"FIRST NAME"
,
"LAST_NAME"
,
"GPA"
);
first_record
=
0
;
}
float
gpa
=
temp
.
gpa
/
100
.
0
;
printf
(
STUDENT_PRINT_FMT_STRING
,
temp
.
id
,
temp
.
fname
,
temp
.
lname
,
gpa
);
}
if
(
first_record
)
{
printf
(
M_DB_EMPTY
)
;
}
return
NO_ERROR
;
}
/*
/*
* print_student
* print_student
* *s: a pointer to a student_t structure that should
* *s: a pointer to a student_t structure that should
...
@@ -321,8 +395,17 @@ int print_db(int fd)
...
@@ -321,8 +395,17 @@ int print_db(int fd)
*/
*/
void
print_student
(
student_t
*
s
)
void
print_student
(
student_t
*
s
)
{
{
// TODO
if
(
s
==
NULL
||
s
->
id
==
0
)
{
printf
(
M_NOT_IMPL
);
printf
(
M_ERR_STD_PRINT
);
return
;
}
printf
(
STUDENT_PRINT_HDR_STRING
,
"ID"
,
"FIRST NAME"
,
"LAST_NAME"
,
"GPA"
);
float
gpa
=
s
->
gpa
/
100
.
0
;
printf
(
STUDENT_PRINT_FMT_STRING
,
s
->
id
,
s
->
fname
,
student
.
lname
,
calculated_gpa_from_s
);
}
}
/*
/*
...
...
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
sign in
to comment