Created
October 8, 2019 19:57
-
-
Save BalintCsala/cf1771a8223e04e0820f9cc122940286 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <ctype.h> | |
// Fontos a bool típushoz | |
#include <stdbool.h> | |
#include <stdlib.h> | |
const char *oszlopok = "abcdefgh"; | |
typedef struct Sakkfigura { | |
int x, y; | |
} sakkfigura; | |
void kiir(sakkfigura figura) | |
{ | |
printf("%c%d", oszlopok[figura.x], figura.y); | |
} | |
sakkfigura beolvas() | |
{ | |
char s[3]; | |
scanf("%s", s); | |
// atoi - Visszaadja egy stringben található számot int-ként | |
// a -97 azért kell, mert a kis "a" ascii kódja 97, így egyszerűen tudunk konvertálni | |
sakkfigura res = { tolower(s[0]) - 97, atoi(&s[1]) }; | |
return res; | |
} | |
bool uti(sakkfigura bastya, sakkfigura masik) | |
{ | |
return bastya.x == masik.x || bastya.y == masik.y; | |
} | |
int main() | |
{ | |
sakkfigura elso = beolvas(); | |
sakkfigura masodik = beolvas(); | |
kiir(elso); | |
printf("\n"); | |
kiir(masodik); | |
printf("\n"); | |
bool szabalyos = uti(elso, masodik); | |
kiir(elso); | |
printf(" "); | |
kiir(masodik); | |
printf(": %s\n", szabalyos ? "szabalyos" : "szabalytalan"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment