forgot to commit this

This commit is contained in:
SowinskiBraeden committed 2025-10-26 12:51:57 -07:00
1 parent 6a53c86e8f
commit f63842d487
14 files changed
+353 -20

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
# Compiler and flags
CC = gcc
CFLAGS = -Wall -std=c11
#Input file
INPUT = input3.txt
OUTPUT = output.txt
REF = ref3.txt
# Source file
SRCS = lab6.c
# Output
TARGET = lab6.out
# Default target
all: $(TARGET)
# Rule to build the executable
$(TARGET): $(SRCS)
$(CC) $(CFLAGS) $(SRCS) -o $(TARGET)
convert_input: $(INPUT)
dos2unix $(REF)
dos2unix $(INPUT)
convert_output: $(OUTPUT)
dos2unix $(OUTPUT)
check: $(OUTPUT) $(REF)
@diff -q $(OUTPUT) $(REF) > /dev/null; \
if [ $$? -eq 0 ]; then \
echo "Pass"; \
else \
echo "Fail"; \
fi
# Rule to run the program
run: $(TARGET)
./$(TARGET) $(INPUT) $(OUTPUT)
# Rule to clean generated files
clean:
rm -f $(TARGET)
+6
View File
@@ -0,0 +1,6 @@
2
2
2
22
11
E
+8
View File
@@ -0,0 +1,8 @@
4
4
0.5
3333
3333
2222
2222
E
+6
View File
@@ -0,0 +1,6 @@
2
2
1
11
22
E
+165
View File
@@ -0,0 +1,165 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
// Update this with your A number
char a_num[] = "01385066";
void writeOutput(char outputPath[], char **arr, int *rows, int *cols)
{
FILE *writeFile;
writeFile = fopen(outputPath, "w");
if (writeFile == NULL)
{
perror("Failed to open output file\n");
return;
}
// matrix to output file
for (int x = 0; x < *rows; x++)
{
for (int y = 0; y < *cols; y++)
{
fputc(arr[x][y], writeFile);
}
if (x < *rows - 1) fputc('\n', writeFile);
}
fclose(writeFile);
}
void zoomArray(char **arr, float n, int *rows, int *cols, char outputFileName[])
{
int newRows = (int)(*rows * n);
int newCols = (int)(*cols * n);
char **scaled = malloc(sizeof(char*) * newRows);
if (scaled == NULL)
{
printf("Failed to malloc scaled");
return;
}
for (int i = 0; i < newRows; i++)
{
scaled[i] = malloc(sizeof(char) * newCols);
if (scaled[i] == NULL)
{
printf("Failed to malloc scaled[i]");
for (int j = 0; j < i; j++)
free(scaled[i]);
free(scaled);
return;
}
}
for (int i = 0; i < newRows; i++) {
for (int j = 0; j < newCols; j++) {
int srcRow = (int)(i / n);
int srcCol = (int)(j / n);
if (srcRow >= *rows) srcRow = *rows - 1;
if (srcCol >= *cols) srcCol = *cols - 1;
scaled[i][j] = arr[srcRow][srcCol];
}
}
writeOutput(outputFileName, scaled, &newRows, &newCols);
}
int main(int argc, char *argv[])
{
if (argc != 3)
{
printf("Usage: %s <input_file> <output_file>\n", argv[0]);
return 1;
}
char *inputFileName = argv[1];
char *outputFileName = argv[2];
char **arr = NULL;
int rows = 0, cols = 0;
float zoomFactor = 0;
// Read the input array from the specified file
FILE *file = fopen(inputFileName, "r");
if (file == NULL)
{
perror("Error opening input file");
return 1;
}
// Read the row value
fscanf(file, "%d", &rows);
// Read the column value
fscanf(file, "%d", &cols);
// Read the zoom factor
fscanf(file, "%f", &zoomFactor);
// Allocate memory for the 2D array
arr = (char **)malloc(rows * sizeof(char *));
if (arr == NULL)
{
printf("Memory allocation failed.\n");
return 1;
}
for (int i = 0; i < rows; i++)
{
arr[i] = (char *)malloc(cols * sizeof(char));
if (arr[i] == NULL)
{
printf("Memory allocation failed.\n");
return 1;
}
}
// Read the elements of the array until 'E' is encountered
char inputChar;
int i = 0, j = 0;
while ((inputChar = fgetc(file)) != 'E')
{
if (inputChar >= '0' && inputChar <= '9' && i < rows && j < cols)
{
arr[i][j++] = inputChar;
if (j == cols)
{
j = 0;
i++;
}
}
}
fclose(file);
printf("A%s\n", a_num);
// Output the input array
printf("Input Array:\n");
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
printf("%c", arr[i][j]);
}
printf("\n");
}
printf("\n");
// Call the zoomArray function
zoomArray(arr, zoomFactor, &rows, &cols, outputFileName);
// Free the memory allocated for the 2D array
for (int i = 0; i < rows; i++)
{
free(arr[i]);
}
free(arr);
return 0;
}
+2
View File
@@ -0,0 +1,2 @@
11
22
+4
View File
@@ -0,0 +1,4 @@
2222
2222
1111
1111
+2
View File
@@ -0,0 +1,2 @@
33
22
+2
View File
@@ -0,0 +1,2 @@
11
22