Hisworld.tistory.com
The hisWorld
(140)
hisworld_new
(0)
hisOld
(138)
Android
(7)
Computer Vision
(18)
JAVA
(4)
C/C++
(26)
열혈강의 C
(32)
TCP/IP socket
(12)
WinAPI
(16)
System Programming
(0)
etc
(23)
Plan
(0)
hisWorld
(0)
hiStory
(0)
hiStudy
(0)
hiSnap
(0)
홈
태그
미디어로그
위치로그
방명록
Windows Live Messenger
winapi
Join C
대학생 공모전
The Turing test page
훈스닷넷
C/C++ Reference
WIKI
/
/
블로그 내 검색
문자
알파벳 갯수 구하기
2008.04.22
알파벳 갯수 구하기
URUZ-7
2008. 4. 22. 18:21
2008. 4. 22. 18:21
텍스트 파일에서 사용된 알파벳의 갯수를 구하기
#include <stdio.h> #include <string.h> #include <conio.h> #define DATA_MAX 52 typedef struct tagData DATA; struct tagData { char alpha; int count; unsigned flag : 1; }; int main(void) { DATA alpha[DATA_MAX] = {0,0,0}; char ch; FILE *fp; int i,cnt; //memset(alpha,0,DATA_MAX); if( (fp=fopen("test.txt","rt"))==NULL) { printf("File Open Failure~!!\n"); } else { while(ch!=EOF) { ch = fgetc(fp); if(ch == ' ' || ch == '\r' || ch=='\n') continue; if(ch >= 'a' || ch <='z' || ch >='A' || 97 <= 'Z') //알파벳일때 { cnt=0; for(i=0; i<DATA_MAX; i++) //구조체 배열을 돌면서 { if(alpha[i].flag == 1) //이미 알파벳이 들어있는 인덱스를 조사해서 if(ch == alpha[i].alpha) //같은 알파벳이 있으면 { alpha[i].count+=1; //갯수를 증가 시켜준다. cnt=1; //값을 저장시켰다는 flag } } if(cnt==0) //기존에 일치하는 알파벳이 없으면 for(i=0; i<DATA_MAX; i++) { if(alpha[i].flag == 0) //비어있는 인덱스를 조사해서 { alpha[i].alpha = ch; //ch를 저장시켜주고 alpha[i].count+=1; //갯수를 증가시켜준다 alpha[i].flag=1; break; } } } else continue; } } fclose(fp); for(i=0; i<DATA_MAX; i++) if(alpha[i].flag==1) printf("%c = %d\n",alpha[i].alpha,alpha[i].count); return 0; }
공유하기
게시글 관리
Hisworld.tistory.com
PREV
이전
1
NEXT
다음
+ Recent posts
Powered by
Tistory
, Designed by
wallel
Rss Feed
and
Twitter
,
Facebook
,
Youtube
,
Google+
티스토리툴바