Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
jobrod
/
Test1
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6c52cd2c
authored
a month ago
by
jobrod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update Jordan Brodie 243483MVEB Test1.c
parent
756cb2fa
master
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
18 deletions
Jordan Brodie 243483MVEB Test1.c
Jordan Brodie 243483MVEB Test1.c
View file @
6c52cd2c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
...
...
@@ -17,34 +18,28 @@ void write_file(const char *filename, Record records[], int length);
void
convert_to_hex
(
int
number
,
char
*
hex
);
int
is_faulty_record
(
const
char
*
line
);
int
get_file_length
(
const
char
*
filename
);
void
close_file
(
FILE
*
file
);
void
print_file_length
(
const
char
*
filename
);
void
process_records
(
Record
records
[],
int
length
);
void
print_processed_records
(
Record
records
[],
int
length
);
void
handle_read_file_error
();
int
main
()
{
Record
records
[
MAX_RECORDS
];
int
length
=
0
;
int
file_length
=
get_file_length
(
"AN.txt"
);
printf
(
"Length of the file: %d lines
\n
"
,
file_length
);
print_file_length
(
"AN.txt"
);
if
(
read_file
(
"AN.txt"
,
records
,
&
length
)
!=
0
)
{
printf
(
"Error reading input file.
\n
"
);
handle_read_file_error
(
);
return
1
;
}
for
(
int
i
=
0
;
i
<
length
;
i
++
)
{
convert_to_hex
(
records
[
i
].
number
,
records
[
i
].
hex
);
}
process_records
(
records
,
length
);
write_file
(
"TUL.txt"
,
records
,
length
);
printf
(
"Processed Records:
\n
"
);
printf
(
"Jnr. I Number I Hex
\n
"
);
for
(
int
i
=
0
;
i
<
length
;
i
++
)
{
printf
(
"%-4d I %-6d I %-4s
\n
"
,
i
+
1
,
records
[
i
].
number
,
records
[
i
].
hex
);
}
print_processed_records
(
records
,
length
);
return
0
;
}
...
...
@@ -78,7 +73,7 @@ int read_file(const char *filename, Record records[], int *length)
}
*
length
=
index
;
fclos
e
(
file
);
close_fil
e
(
file
);
return
0
;
}
...
...
@@ -97,7 +92,7 @@ void write_file(const char *filename, Record records[], int length)
fprintf
(
file
,
"%-4d I %-6d I %-4s
\n
"
,
i
+
1
,
records
[
i
].
number
,
records
[
i
].
hex
);
}
fclos
e
(
file
);
close_fil
e
(
file
);
}
void
convert_to_hex
(
int
number
,
char
*
hex
)
...
...
@@ -131,6 +126,40 @@ int get_file_length(const char *filename)
count
++
;
}
fclos
e
(
file
);
close_fil
e
(
file
);
return
count
;
}
void
close_file
(
FILE
*
file
)
{
fclose
(
file
);
}
void
print_file_length
(
const
char
*
filename
)
{
int
file_length
=
get_file_length
(
filename
);
printf
(
"Length of the file: %d lines
\n
"
,
file_length
);
}
void
process_records
(
Record
records
[],
int
length
)
{
for
(
int
i
=
0
;
i
<
length
;
i
++
)
{
convert_to_hex
(
records
[
i
].
number
,
records
[
i
].
hex
);
}
}
void
print_processed_records
(
Record
records
[],
int
length
)
{
printf
(
"Processed Records:
\n
"
);
printf
(
"Jnr. I Number I Hex
\n
"
);
for
(
int
i
=
0
;
i
<
length
;
i
++
)
{
printf
(
"%-4d I %-6d I %-4s
\n
"
,
i
+
1
,
records
[
i
].
number
,
records
[
i
].
hex
);
}
}
void
handle_read_file_error
()
{
printf
(
"Error reading input file.
\n
"
);
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment