Added ability to choose type of drawing triangle
This commit is contained in:
parent
f9020d0b9b
commit
d7ce96aae8
97
triangle.c
97
triangle.c
@ -1,37 +1,58 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
void clrscr();
|
void clrscr();
|
||||||
void drawTriangle(char *type, int height, char symbol1, char symbol2);
|
bool strcomp(char *a, char *b);
|
||||||
|
void drawTriangle(char type[3], int height, char symbol1, char symbol2);
|
||||||
void drawLine(int freeSpace, int length, char symbol);
|
void drawLine(int freeSpace, int length, char symbol);
|
||||||
|
void getTriangleOptions(char *type);
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
while (1)
|
clrscr();
|
||||||
|
printf("\n\n");
|
||||||
|
printf(" * Welcom to The Triangle programm.\n");
|
||||||
|
printf(" *** It would help you to draw some simple, but beautiful triangles.\n");
|
||||||
|
printf("***** Hope you'll enjoy using it!\n");
|
||||||
|
printf("\n\n");
|
||||||
|
|
||||||
|
sleep(2);
|
||||||
|
|
||||||
|
clrscr();
|
||||||
|
|
||||||
|
drawTriangle("so", 5, '*', '\0');
|
||||||
|
printf("(so)lid\n");
|
||||||
|
|
||||||
|
drawTriangle("st", 5, '*', '+');
|
||||||
|
printf("(st)ripped\n");
|
||||||
|
|
||||||
|
printf("Select what mode do you want to work with: ");
|
||||||
|
|
||||||
|
char type[3];
|
||||||
|
fgets(type, 3, stdin);
|
||||||
|
|
||||||
|
printf("%s. Great choise!\n", ((type == "so") ? "Solid" : "Stripped"));
|
||||||
|
|
||||||
|
int height;
|
||||||
|
printf("Height of triangle: ");
|
||||||
|
scanf("%d", &height);
|
||||||
|
getchar();
|
||||||
|
|
||||||
|
char symbol1;
|
||||||
|
printf("Primary symbol: ");
|
||||||
|
symbol1 = getchar();
|
||||||
|
getchar();
|
||||||
|
|
||||||
|
char symbol2;
|
||||||
|
if (strcomp(type, "st"))
|
||||||
{
|
{
|
||||||
clrscr();
|
printf("Secondary symbol: ");
|
||||||
printf("\n\n");
|
symbol2 = getchar();
|
||||||
printf(" * Welcom to The Triangle programm.\n");
|
|
||||||
printf(" *** It would help you to draw some simple, but beautiful triangles.\n");
|
|
||||||
printf("***** Hope you'll enjoy using it!\n");
|
|
||||||
printf("\n\n");
|
|
||||||
|
|
||||||
sleep(2);
|
|
||||||
|
|
||||||
clrscr();
|
|
||||||
printf("\n\n");
|
|
||||||
printf("Select what mode do you want to work with:\n");
|
|
||||||
|
|
||||||
drawTriangle("so", 5, '*', '0');
|
|
||||||
printf("(so)lid\n");
|
|
||||||
|
|
||||||
drawTriangle("st", 5, '*', '+');
|
|
||||||
printf("(st)ripped\n");
|
|
||||||
|
|
||||||
char type[2];
|
|
||||||
fgets(type, 2, stdin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drawTriangle(type, height, symbol1, symbol2);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,18 +61,33 @@ void clrscr()
|
|||||||
printf("\e[1;1H\e[2J");
|
printf("\e[1;1H\e[2J");
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawTriangle(char *type, int height, char symbol1, char symbol2)
|
bool strcomp(char *a, char *b)
|
||||||
{
|
{
|
||||||
if (!(strncmp(type, "so", 2)))
|
int i = 0;
|
||||||
|
while (a[i] != '\0' && a[i] != '\n')
|
||||||
|
{
|
||||||
|
if (a[i] != b[i])
|
||||||
|
return false;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (a[i] != '\0' || b[i] != '\0')
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawTriangle(char type[3], int height, char symbol1, char symbol2)
|
||||||
|
{
|
||||||
|
if (strcomp(type, "so"))
|
||||||
{
|
{
|
||||||
symbol2 = symbol1;
|
symbol2 = symbol1;
|
||||||
}
|
}
|
||||||
else if (!(strncmp(type, "st", 2)))
|
else if (strcomp(type, "st"))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("Wrong input, try angain");
|
printf("Wrong input, try angain\n");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < height; i++)
|
for (int i = 0; i < height; i++)
|
||||||
@ -80,4 +116,9 @@ void drawLine(int freeSpace, int length, char symbol)
|
|||||||
putchar(symbol);
|
putchar(symbol);
|
||||||
}
|
}
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
void getTriangleOptions(char *type)
|
||||||
|
{
|
||||||
|
printf("");
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user