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 | #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { char s1[1001] = {0}; char *ptr = NULL; int nCnt = 0; printf("1000자 이하로 입력하세요(알파벳만): "); scanf("%[^\n]s", s1); ptr = strchr(s1, ' '); while(ptr != NULL) { nCnt++; ptr = strchr(ptr+1, ' '); } printf("공백문자의 갯수: %d\n", nCnt); return 0; } | cs |
scanf("%[^\n]s", s1);
공백 문자를 입력 받으려면 위와 같이 %s 사이에 []브라켓 ^캐럿 \n백슬래쉬엔을 입력해야 한다.
'programming' 카테고리의 다른 글
nth-of-type, nth-child (0) | 2019.04.08 |
---|---|
구글 스프레드 시트 - 조건부 서식 - 행에 색깔 넣기 (0) | 2019.04.04 |
우분투에서 mysql 접속이 안 되었을 때 (0) | 2019.04.02 |
factorial (0) | 2019.03.30 |
c) c언어코딩도장 the 갯수 (0) | 2019.01.05 |