-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.c
54 lines (40 loc) · 794 Bytes
/
input.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
50
51
52
53
54
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <ctype.h>
void digest()
{
int c;
/* consumimos hasta algun caracter relevante */
while((c=getchar()) != EOF && isspace(c));
/* si es un comentario */
if(c == '#')
{
while((c=getchar()) != '\n' && c != EOF);
digest();
} else ungetc(c,stdin);
}
void exitwerr(char* errdesc, ...)
{
va_list vl;
va_start(vl,errdesc);
vfprintf(stderr,errdesc,vl);
va_end(vl);
exit(1);
}
int readInt()
{
int x;
digest();
if(scanf("%i",&x) != 1)
exitwerr("Entrada mal formada (Se esperaba un int en pos %li).\n",ftell(stdin));
return x;
}
double readDouble()
{
double x;
digest();
if(scanf("%lf",&x) != 1)
exitwerr("Entrada mal formada (Se esperaba un double en pos %li).\n",ftell(stdin));
return x;
}