Last active
August 29, 2015 14:08
-
-
Save olegoid/9fa2db5661c2b2b263d5 to your computer and use it in GitHub Desktop.
My version of your task
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
// | |
// main.c | |
// AnnaTest | |
// | |
// Created by Oleg Demchenko on 10/29/14. | |
// Copyright (c) 2014 Oleg Demchenko. All rights reserved. | |
// | |
#include <stdio.h> | |
#include<ctype.h> | |
int main(int argc, const char * argv[]) { | |
int x, x1, x2, x3, y, y1, y2, y3; | |
set_coordinates (1, &x, &y); | |
set_coordinates (2, &x1, &y1); | |
set_coordinates (3, &x2, &y2); | |
set_coordinates (4, &x3, &y3); | |
if (x == x3 && x1 == x2 && y == y1 && y2 == y3 && y1 != y2 && x1 != x3) | |
printf("mozno\n"); | |
else | |
printf("nelze\n"); | |
return 0; | |
} | |
int set_coordinates (int pointNumber, int* x, int* y) | |
{ | |
printf("Point #%d\n", pointNumber); | |
if (get_integer("Enter X\n", &x)) { | |
; // End of file or I/O error (rare) | |
} | |
if (get_integer("Enter Y\n", &y)) { | |
; // End of file or I/O error (rare) | |
} | |
return 0; | |
} | |
int get_integer(const char *prompt, int *i) { | |
int Invalid = 0; | |
int EndIndex; | |
char buffer[100]; | |
do { | |
if (Invalid) | |
fputs("Invalid input, try again.\n", stdout); | |
Invalid = 1; | |
fputs(prompt, stdout); | |
if (NULL == fgets(buffer, sizeof(buffer), stdin)) | |
return 1; | |
} while ((1 != sscanf(buffer, "%d %n", i, &EndIndex)) || buffer[EndIndex]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment