Skip to content

Instantly share code, notes, and snippets.

@olegoid
Created October 29, 2014 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olegoid/98f2038cbf36addf3548 to your computer and use it in GitHub Desktop.
Save olegoid/98f2038cbf36addf3548 to your computer and use it in GitHub Desktop.
new version
//
// 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>
void set_coordinates (const int pointNumber, int *x, int *y)
{
printf("Point #%d\n", pointNumber);
int xCoordinate = 0;
int yCoordinate = 0;
if (get_integer("Enter X\n", &xCoordinate)) {
; // End of file or I/O error (rare)
}
if (get_integer("Enter Y\n", &yCoordinate)) {
; // End of file or I/O error (rare)
}
*x = xCoordinate;
*y = yCoordinate;
}
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);
printf("Point %d", x);
printf("Point %d", x1);
printf("Point %d", x2);
printf("Point %d", x3);
if (x == x3 && x1 == x2 && y == y1 && y2 == y3 && y1 != y2 && x1 != x3)
printf("mozno\n");
else
printf("nelze\n");
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