C作业笔记

 

代码
1 /*
2 date : 2010-7-17
3 FileName : Lession4.Cpp
4 Author : jeamy
5 Content : Count lines , words , and characters in input
6  */
7  /*
8 #include <stdio.h>
9 #define IN 0
10 #define OUT 1
11
12 void main()
13 {
14 int c,nl,nw,nc,State;
15 c = nl = nw = nc = 0;
16 State = OUT;
17 do
18 {
19 c = getchar();
20 if (c == '\n')
21 ++nl;
22 if (c == '\n' || c == '\t' || c == ' ')
23 State = OUT;
24 if (State == OUT){
25 State = IN;
26 ++nw;
27 }
28 }while(c != 'E');
29 printf("have %d lines , %d words \n",nl,nw);
30 }
31  */
32
33  /* exeicise */
34
35 #include <stdio.h>
36 #define IN 0
37 #define OUT 1
38 void main()
39 {
40 /* Function 1 */
41
42 int c,state ;
43 c = state = OUT;
44 do
45 {
46 c = getchar();
47 if (c == 'E')
48 return 0;
49 if (c == ' ' || c == '\t' || c == '\n'){
50 if (state == IN){
51 putchar('\n'); /* the word finished */
52 state = OUT;
53 }
54 }else if( state == OUT){
55 putchar(c); /* begin or end of the word */
56 state = IN;
57 }else{
58 putchar(c); /* insdie of the word */
59 }
60 }while(true);
61
62 /* Function 2 */
63 // int c;
64 // do{
65 // c =getchar();
66 // if (c == ' ' || c == '\t' || c == '\n'){
67 // putchar('\n');
68 // }else{
69 // putchar(c);
70 // }
71 // }while(true);
72 }

 

 

 

代码很简单,不过功能不错,想看效果,试试就知道!
posted @ 2010-07-19 11:22  莫问哥哥  阅读(114)  评论(0)    收藏  举报