-
Notifications
You must be signed in to change notification settings - Fork 103
/
rostring.c
51 lines (48 loc) · 1.11 KB
/
rostring.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
#include <unistd.h>
void write_word(char *start, char *end)
{
while (start < end)
{
write(1, start, 1);
start++;
}
}
int main(int argc, char **argv)
{
char *str;
char *first_word_start;
char *first_word_end;
if (argc > 1)
{
str = argv[1];
while (*str == ' ' || *str == '\t')
str++;
first_word_start = str;
while (*str && *str != ' ' && *str != '\t')
str++;
first_word_end = str;
while (*str == ' ' || *str == '\t')
str++;
if (*str) {
while (*str)
{
if (*str == ' ' || *str == '\t')
{
while (*str == ' ' || *str == '\t')
str++;
if (*str)
write(1, " ", 1);
}
else
{
write(1, str, 1);
str++;
}
}
write(1, " ", 1);
}
write_word(first_word_start, first_word_end);
}
write(1, "\n", 1);
return 0;
}