-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrostring.c
More file actions
94 lines (78 loc) · 1.18 KB
/
rostring.c
File metadata and controls
94 lines (78 loc) · 1.18 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <unistd.h>
#include <stdio.h>
int isSpace (char c)
{
return ((c ==32 || (c >= 9 && c <= 13))?1:0);
}
int newLen(char * s)
{
int i = 0;
while (s[i] != '\0')
i++;
while (i != 0 && isSpace(s[i-1]))
i--;
return i;
}
int wC (char *s)
{
int i, len = 0, flag;
i = 0;
while (s[i] != '\0')
{
flag = 0;
while (s[i] != '\0' && (isSpace(s[i])))
i++;
while (s[i] != '\0' && (!isSpace(s[i])))
{
flag = 1;
i++;
}
len+= ((flag ==1)?1:0);
}
return len;
}
void printFirstW(char *s)
{
int i = 0;
while (s[i] != '\0' && isSpace(s[i]))
i++;
while (s[i]!='\0' && !isSpace(s[i]))
{
write(1, &s[i], 1);
i++;
}
}
int main (int ac, char ** av)
{
int flag = 0;
int i = 0;
if (ac < 2)
{
write(1, "\n", 1);
return 1;
}
while (av[1][i] != '\0')
{
int wc = 0;
while (isSpace(av[1][i]) && av[1][i] != '\0')
i++;
if (!isSpace(av[1][i]) && av[1][i] != '\0' && flag == 0)
{
flag = 1;
while (!isSpace(av[1][i]) && av[1][i] != '\0')
{
i++;
}
}
while (!isSpace(av[1][i]) && av[1][i] != '\0' && flag == 1)
{
write(1, &av[1][i], 1);
i++;
wc = 1;
}
if (wc == 1)
write(1, " ", 1);
}
printFirstW(av[1]);
return 0;
}