|
일단 힌트만 드리겠씁니다.
첫번째 character는 항상 맨 처음만 가리키게됩니다.
두번째 위와 동일
세번째것 처럼 character[i] 형식으로 하던가 해야 함.
세번째 for 문의위치가 잘못되었슴.
이건 플로우차트를 한번 그려보시면.. 단번에 이해를 하실수 있을겁니다.
박중혁 님이 쓰신 글 :
: 제가 하면서 한 3가지 경우로 만들어 봤는데...뭐가 잘못됬는지...고수분들의 조언 부탁 드립니다...
:
: 맨첫번째가..
:
: #include <stdio.h>
: #include <ctype.h>
: void main(void)
: {char character[50];
: void find_x(char[]);
: printf("type a sentance: ");
: gets(character);
: find_x(character);
: }
:
: void find_x(char character[])
: {
: int blank=0,alpha=0,digit=0,other=0;
: while ((char)character!='\n')
: {
: if ((char) character==' ')
: ++blank;
: else if (isalpha((char)character))
: ++alpha;
: else if (isdigit((char)character))
: ++digit;
: else
: ++other;
: }
: printf("알파벳:%s 숫자:%s 그외%s",alpha,digit,other+blank);
: }
:
: 두번째가
: #include <stdio.h>
: #include <ctype.h>
: void main(void)
: {char character[50];
: void find_x(char[]);
: printf("type a sentance: ");
: gets(character);
: find_x(character);
: }
:
: void find_x(char character[])
: {
: int c,blank=0,alpha=0,digit=0,other=0;
: while ((c=getchar())!='\o')
: if ((char) c==' ')
: ++blank;
: else if (isalpha(c))
: ++alpha;
: else if (isdigit(c))
: ++digit;
: else
: ++other;
:
: printf("알파벳:%s 숫자:%s 그외",alpha,digit,other+blank);
: }
:
: 마지막으로...
: #include <stdio.h>
: #include <ctype.h>
: void main(void)
: {char character[50];
: void find_x(char[]);
: printf("type a sentance: ");
: gets(character);
: find_x(character);
: }
:
: void find_x(char character[])
: {
: int i,c,blank=0,alpha=0,digit=0,other=0;
: while(character[i]!='\o')
: {
: for (i=0;i<50;++i)
: {
: if (character[i]==' ')
: ++blank;
: else if (isalpha(character[i]))
: ++alpha;
: else if (isdigit(character[i]))
: ++digit;
: else
: ++other;
: }
:
: }
: printf("알파벳:%s 숫자:%s 그외",alpha,digit,other+blank);
: }
:
: 먼가 쉬운것이 잘못된거 같은데 잘모르겠네요...좀 허접 하더라도 양해 부탁 드립니다...
|