Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

jobrod / Test1

  • This project
    • Loading...
  • Sign in
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 2 months ago by jobrod's avatar 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 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;
fclose(file);
close_file(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);
}
fclose(file);
close_file(file);
}
void convert_to_hex(int number, char *hex)
......@@ -131,6 +126,40 @@ int get_file_length(const char *filename)
count++;
}
fclose(file);
close_file(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% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment