728x90
반응형
#include <stdio.h>
#include <ctype.h>
int read_line_with_compression(char *compressed, const int limit);
int main()
{
char line[100];
while (1)
{
printf("$ ");
int length = read_line_with_compression(line, 100);
printf("%s : %d\n", line, length);
}
return 0;
}
int read_line_with_compression(char *compressed, const int limit)
{
int ch; int i = 0;
while ((ch = getchar()) != '\n')
{
if (i < limit - 1 && (!isspace(ch)) || i >0 && !isspace(compressed[i - 1]))
{
compressed[i++] = ch;
}
}
if (i > 0 && isspace(compressed[i - 1]))
i--;
compressed[i] = '\0';
return i;
}
//c로 배우는 자료구조 및 여러가지 예제 실습 by권오흠교수님 in 인프런
728x90
반응형
'프로그래밍 언어 > c study' 카테고리의 다른 글
c 언어 전화번호부 .version.1.0 (0) | 2021.02.19 |
---|