-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathentrada.c
49 lines (44 loc) · 1.05 KB
/
entrada.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "funcoes.h"
void limpar_teclado(){
int tc;
tc=getchar();
while(tc!='\n' && tc!=EOF){tc=getchar();}
}
unsigned short int leitura(unsigned short int *x, unsigned short int *y){
unsigned short int ent, coordx=0, coordy=0;
*x=0;
*y=0;
ent=getchar();
while(ent!='\0' && ent!='\n' && ent!=EOF){
if(ent>='0' && ent<'9'){
*x=((*x)*10)+(ent-'0');
coordx+=1;
}else if(ent>='A' && ent<='L'){
*y=((*y)*10)+(ent-'A');
coordy+=3;
}else if(ent>='a' && ent<='l'){
*y=((*y)*10)+(ent-'a');
coordy+=3;
}else if((ent>='M' && ent<='Z')||(ent>='m' %%ent<='z')){
coordy+=6;
}
ent=getchar();
}
return (coordx+coordy);
}
void entrada(unsigned short int *x, unsigned short int *y){
unsigned short int coord;
do{
printf("Insira as coordenadas: ");
limpar_teclado();
coord=leitura(x, y);
if((*x)>12 || (*y)>12 || coord<3 || coord>5){
printf("Entrada inválida!\n");
}else{
printf("Entendido capitão!\n");
}
}while((*x)>12 || (*y)>12 || coord<3 || coord>5);
}