-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths_gets.h
66 lines (54 loc) · 859 Bytes
/
s_gets.h
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
63
64
65
66
#ifndef _S_GETS_H
#define _S_GETS_H
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdbool.h>
char * s_gets (char *st, int n);
char * s_gets_1 (char * st, int n);
inline static void eatline (void)
{
while (getchar () != '\n');
}
char * s_gets (char * st, int n)
{
char * ret_val;
ret_val = fgets(st, n, stdin);
if (ret_val)
{
while ((*st != '\n') && (*st))
{
*st ++;
}
if (*st == '\n')
{
*st = '\0';
}else
{
eatline ();
}
}else
{
ret_val = "No result. \n";
}
return ret_val;
}
char * s_gets_1 (char * st, int n)
{
char * ret_val, * find;
ret_val = fgets (st, n, stdin);
if (ret_val)
{
find = strchr (st, '\n');
if (find)
{
*find = '\0';
}else
{
eatline ();
}
}
return ret_val;
}
#endif