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
Mar 04, 2025
by
jobrod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update Jordan Brodie 243483MVEB Test1.c
parent
756cb2fa
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 <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
...
@@ -17,34 +18,28 @@ void write_file(const char *filename, Record records[], int length);
...
@@ -17,34 +18,28 @@ void write_file(const char *filename, Record records[], int length);
void
convert_to_hex
(
int
number
,
char
*
hex
);
void
convert_to_hex
(
int
number
,
char
*
hex
);
int
is_faulty_record
(
const
char
*
line
);
int
is_faulty_record
(
const
char
*
line
);
int
get_file_length
(
const
char
*
filename
);
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
()
int
main
()
{
{
Record
records
[
MAX_RECORDS
];
Record
records
[
MAX_RECORDS
];
int
length
=
0
;
int
length
=
0
;
int
file_length
=
get_file_length
(
"AN.txt"
);
print_file_length
(
"AN.txt"
);
printf
(
"Length of the file: %d lines
\n
"
,
file_length
);
if
(
read_file
(
"AN.txt"
,
records
,
&
length
)
!=
0
)
if
(
read_file
(
"AN.txt"
,
records
,
&
length
)
!=
0
)
{
{
printf
(
"Error reading input file.
\n
"
);
handle_read_file_error
(
);
return
1
;
return
1
;
}
}
for
(
int
i
=
0
;
i
<
length
;
i
++
)
process_records
(
records
,
length
);
{
convert_to_hex
(
records
[
i
].
number
,
records
[
i
].
hex
);
}
write_file
(
"TUL.txt"
,
records
,
length
);
write_file
(
"TUL.txt"
,
records
,
length
);
print_processed_records
(
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
);
}
return
0
;
return
0
;
}
}
...
@@ -78,7 +73,7 @@ int read_file(const char *filename, Record records[], int *length)
...
@@ -78,7 +73,7 @@ int read_file(const char *filename, Record records[], int *length)
}
}
*
length
=
index
;
*
length
=
index
;
fclos
e
(
file
);
close_fil
e
(
file
);
return
0
;
return
0
;
}
}
...
@@ -97,7 +92,7 @@ void write_file(const char *filename, Record records[], int length)
...
@@ -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
);
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
)
void
convert_to_hex
(
int
number
,
char
*
hex
)
...
@@ -131,6 +126,40 @@ int get_file_length(const char *filename)
...
@@ -131,6 +126,40 @@ int get_file_length(const char *filename)
count
++
;
count
++
;
}
}
fclos
e
(
file
);
close_fil
e
(
file
);
return
count
;
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
"
);
}
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