英文单词填词

 1 #include <stdio.h>
 2 
 3 /*
 4     name: 填字游戏/Spell Word Game
 5     author :qilei
 6     date: 2013-07-23
 7 
 8 */
 9 
10 
11 #define WORD_MAX_LENGTH 10
12 int main()
13 {
14     char wordFir[WORD_MAX_LENGTH],wordSec[WORD_MAX_LENGTH];
15     printf("请输入10个字母以内的单词:\n");
16     scanf("%s %s", wordFir, wordSec);
17     int i,j;
18     int wordFirPos=0, wordSecPos=0;
19     bool sameChar = 0;
20     for(i=0; wordFir[i]&&!sameChar; i++)
21         for(j=0; wordSec[j]&&!sameChar; j++)
22             if (wordFir[i] - wordSec[j] == 0)
23             {
24                 sameChar = 1;
25                 wordFirPos = i;
26                 wordSecPos = j;
27             }
28             if(sameChar)
29             {
30                 printf("The position in string are: %d and %d\n" , wordFirPos, wordSecPos);
31             }else
32             {
33                 printf("None the same character\n");
34                 return 0;
35             }
36 
37     /*
38         format the ouput
39     */
40     for(i = 0; wordSec[i]; i++)
41     {
42         if(i == wordSecPos)
43             printf("%s\n", wordFir);
44         else
45         {
46             printf("%*.*c\n", wordFirPos+1, 1, wordSec[i] );
47         }
48     }
49     return 0;
50 }

 

posted @ 2013-07-23 18:25  HolyGrail  阅读(546)  评论(0编辑  收藏  举报
设计良好的程序将用户的注意力视为有限的宝贵资源,只有在必要时才要求使用。 ——《Unix编程艺术》