문제 :

입력 파일 :

[sample.txt

0.00MB](https://blog.kakaocdn.net/dna/I5Kf9/btqA7q3zbiX/AAAAAAAAAAAAAAAAAAAAANrvSUHPXY9pb861NzszU1ZSjedb5bh_Z-XW6gY7gY7Q/sample.txt?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&expires=1788188399&allow_ip=&allow_referer=&signature=Z3BB1PLUPoQ6gz717fxkZL1UeNg%3D&attach=1&knm=tfile.txt)

실행 결과 :

소스 코드 :

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 63 64 65 #include <stdio.h> #include <string.h> #include <stdlib.h> void get_token_num(char *bp, int *num, int *alpha, int *other) { char *cp; int i, count1, count2; for(cp = strtok(bp, " \t\n"); cp != NULL;){ if(‘A’ <= cp[0] && ‘Z’ >= cp[0]) count1 = -1; else if(‘0’ <= cp[0] && ‘9’ >= cp[0]) count1 = 0; else{ count1 = 1; count2 = 1; break; } int len = strlen(cp); for(i=0; i<len; i++){ if ( ‘A’ <= cp[i] && ‘Z’ >= cp[i]) count2 = -1; else if ( ‘0’ <= cp[i] && ‘9’ >= cp[i]) count2 = 0; else count2 = 1; if(count2 != count1){ count2 = 1; break; } } switch(count2) { case -1 : *alpha += 1; break; case 0  : *num += 1; break; case 1  : *other += 1; break; default : fprintf(stderr,“error…\n”); exit(2); } cp = strtok(NULL," \t\n"); } } int main(){ FILE *fp; char buf[80]; int num = 0, alpha=0, other=0; if((fp = fopen(“sample.s”, “r”)) == NULL){ fprintf(stderr, “file not found…\n”); exit(1); } while(fgets(buf, sizeof(buf), fp) != NULL){ get_token_num(buf, &num, &alpha, &other); } fclose(fp); printf(“Number = %d\n”, num); printf(“Alphabet = %d\n”, alpha); printf(“Other = %d\n”, other); return 0; }

설명 :

Token을 잘라서 숫자 단어인지 알파벳 단어인지 기타 다른 단어인지만 판별 해주면 되는 프로그램이라 구현이 어렵지 않기 때문에 주석을 달지 않았습니다.

공유하기

게시글 관리

코딩은 내일부터 ;

저작자표시 (새창열림)

💻 개발 & CS > 시스템 & 임베디드’ 카테고리의 다른 글

시스템 프로그래밍 프로젝트 #7 최종 (Assembler in C)  (2) 2020.03.19
시스템 프로그래밍 프로젝트 #1  (1) 2020.01.12
시스템 프로그래밍 프로젝트 #3  (1) 2020.01.12
시스템 프로그래밍 프로젝트 #4  (1) 2019.12.19
시스템 프로그래밍 프로젝트 #5  (1) 2019.11.23