-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathused.c
More file actions
62 lines (55 loc) · 1.33 KB
/
used.c
File metadata and controls
62 lines (55 loc) · 1.33 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
#include <stdio.h>
#ifndef _CPLUSPLUS
typedef int bool;
#define true 1
#define false 0
#endif
int getch(void); /* чтение символов с преобразованием */
void uSED(void); /* micro stream editor */
main()
{
uSED();
return 0;
}
void uSED(void)
{
int nlch = 0; /* newline character */
int c;
bool lastspace=false;
while (isspace(c = getch()) && c != EOF) /*пропускаем первые "белые" символы*/
;
ungetc(c,stdin);
while ((c = getch()) != EOF) {
switch(c) {
case '\n':
nlch++;
case ' ':
lastspace=true;
break;
case EOF:
putchar('\n');
break;
default:
if(lastspace)
putchar(nlch>1?'\n':' ');
putchar(c);
lastspace=false;
nlch=0;
break;
}
}
/* не забываем про последний символ :)*/
//< putchar(EOF); здесь будет напечатано '\0xff'. Для закрытия потока используют fclose(file)
}
int getch(void)
{
int c,nc;
if((c=getchar())=='<')
if((nc=getchar())=='>') {
ungetc('\n',stdin);
return '\n';
}
else ungetc(nc,stdin);
if(isspace(c) && c!='\n') c=' ';
return c;
}