blob: d04da1ec6380e180bf8b52ab9e1790fcc91e22ec (
plain) (
blame)
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
|
#include <stdio.h>
#include <ctype.h>
#define MAXLEN 1000
int atoi(char str[]);
int sneed_getline(char str[], int max);
int
main(void)
{
char str[MAXLEN];
while (sneed_getline(str, MAXLEN)) {
printf("string ver : %s", str);
printf("int ver : %d\n", atoi(str));
}
return 0;
}
int
atoi(char str[])
{
int val;
for (val = 0; isdigit(*str) && *str; str++)
val = val * 10 + *str -'0';
return val;
}
int
sneed_getline(char str[], int max)
{
char input;
char *str_og = str;
while (--max && (*str = input = getchar()) != EOF && input != '\n')
str++;
if (!max && input != '\n')
*str = '\n', str++;
str = '\0';
return str - str_og -1;
}
|