final lab05 passes
This commit is contained in:
2 files changed
+33
-5
No files matched your search
+1
-1
@@ -5,7 +5,7 @@ CFLAGS = -Wall -std=c11
|
|||||||
#Input file
|
#Input file
|
||||||
INPUT = input2.txt
|
INPUT = input2.txt
|
||||||
OUTPUT = output.txt
|
OUTPUT = output.txt
|
||||||
REF = ref.txt
|
REF = ref2.txt
|
||||||
# Source file
|
# Source file
|
||||||
SRCS = lab5.c
|
SRCS = lab5.c
|
||||||
# Output
|
# Output
|
||||||
|
|||||||
+32
-4
@@ -94,7 +94,7 @@ void drawShape(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert coords into matrix
|
// Plot coordinates in matrix
|
||||||
for (int i = 0; i < numCoords; i++)
|
for (int i = 0; i < numCoords; i++)
|
||||||
{
|
{
|
||||||
int x = *(*(coords + i));
|
int x = *(*(coords + i));
|
||||||
@@ -132,14 +132,28 @@ void drawShape(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear spaces
|
||||||
|
|
||||||
// matrix to output file
|
// matrix to output file
|
||||||
for (int y = 0; y < height; y++)
|
for (int y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
for (int x = 0; x < width; x++)
|
// only print up until last '*', dont
|
||||||
|
// print trailing spaces
|
||||||
|
int lastPoint;
|
||||||
|
for (int i = width - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
if (*(*(matrix + i) + y) == '*')
|
||||||
|
{
|
||||||
|
lastPoint = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int x = 0; x <= lastPoint; x++)
|
||||||
{
|
{
|
||||||
fputc(*(*(matrix + x) + y), writeFile);
|
fputc(*(*(matrix + x) + y), writeFile);
|
||||||
}
|
}
|
||||||
fputc('\n', writeFile);
|
if (y < height - 1) fputc('\n', writeFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(writeFile);
|
fclose(writeFile);
|
||||||
@@ -187,7 +201,7 @@ int main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i< MAX_COORDS; i++)
|
for (int i = 0; i < MAX_COORDS; i++)
|
||||||
{
|
{
|
||||||
*(coords + i) = malloc(COORD_2D * sizeof(int));
|
*(coords + i) = malloc(COORD_2D * sizeof(int));
|
||||||
|
|
||||||
@@ -220,6 +234,20 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (fscanf(inputFile, "%d", &x) == 0 ||
|
||||||
|
fscanf(inputFile, "%d", &x) == 0)
|
||||||
|
{
|
||||||
|
// Free and close file before exiting
|
||||||
|
for (int i = 0; i < MAX_COORDS; i++) {
|
||||||
|
free(coords[i]);
|
||||||
|
}
|
||||||
|
free(coords);
|
||||||
|
fclose(inputFile);
|
||||||
|
|
||||||
|
perror("Error: bad input file\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
char c;
|
char c;
|
||||||
if (fscanf(inputFile, " %c", &c) == 1 && c == 'E') {
|
if (fscanf(inputFile, " %c", &c) == 1 && c == 'E') {
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in new issue
Block a user