#include <stdio.h>
#define ReadLine( x ) (getline((x), sizeof((x))))
/* getline: get line into s, return length */
int getline(char s[], int lim) {
int c, i;
i = 0;
while (--lim > 0 && (c = getchar()) != EOF && c != '\n')
s[i++] = c;
if (c == '\n')
s[i] = 0x00; //s[i++] = c;
s[i] = '\0';
return i;
}
int main() {
char s[256];
puts("What's your name?");
int i = ReadLine(s); //getline(s, sizeof(s));
printf("Hi, %s\n", s);
printf("%d letters long.", i);
return 0;
}
'C 언어' 카테고리의 다른 글
| strtok 함수 구현 (0) | 2022.03.11 |
|---|---|
| C언어 2차원 문자열 어레이 동적 생성 (0) | 2021.12.19 |
| C 언어 substring 함수 구현 방법 (1) | 2021.11.23 |
| C언어 개인 프로젝트 (매크로 함수 이용) (0) | 2021.10.26 |
| C 언어 endswith 함수 구현 (0) | 2021.10.22 |
댓글