-
Notifications
You must be signed in to change notification settings - Fork 165
/
runtime.c
62 lines (52 loc) · 927 Bytes
/
runtime.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
55
56
57
58
59
60
61
62
#include <stdio.h>
char buf[128];
void printError()
{
printf("Program called error!");
exit(-1);
}
int readInt()
{
for(;;) {
int v;
fgets(buf,sizeof(buf),stdin);
if(1 == sscanf(buf,"%d",&v))
return v;
else {
if(strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
buf[strlen(buf)-1] = 0;
printf("\"%s\" is not an int, try again:",buf);
}
}
}
double readDouble(void)
{
for(;;) {
double v;
fgets(buf,sizeof(buf),stdin);
if(1 == sscanf(buf,"%lg",&v))
return v;
else {
if(strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
buf[strlen(buf)-1] = 0;
printf("\"%s\" is not a double, try again:",buf);
}
}
}
void printInt(int v)
{
printf("%d\n",v);
}
void printDouble(double v)
{
printf("%f\n",v);
}
void printString(char* s)
{
printf("%s\n",s);
}
int main () {
printInt(7 * readInt ()) ;
printDouble(3.14);
printString("hello");
}