黑马程序员技术交流社区

标题: 一个小小的程序 今天的总结,,, [打印本页]

作者: sunshine429    时间: 2016-1-2 22:45
标题: 一个小小的程序 今天的总结,,,
  1. #include <stdio.h>



  2. void main()
  3. {
  4.       char str[40];
  5.       int cmp( char *str1, char *str2 );

  6.       printf("Please enter the people you like the best : ");
  7.       scanf("%s", str);

  8. #ifndef CORRECT
  9. #define CORRECT "sunshine429"
  10. #endif

  11.       if( cmp( str, CORRECT ) == 0 )
  12.       {
  13.             printf("\nYeah! You are a smart man!\n\n");
  14.       }
  15.       else
  16.       {
  17.             printf("\nYou fool! Man!!\n\n");
  18.       }

  19. }

  20. int cmp( char *str1, char *str2 )
  21. {
  22.       int i = 0, j = 0;

  23.       while( str1[i] )
  24.       {
  25.             while( str2[j] == str1[i] )
  26.             {
  27.                   i++;
  28.                   j++;
  29.                   if( !str2[j] )
  30.                   {
  31.                         return 0;
  32.                   }
  33.             }
  34.             j = 0;
  35.             i++;
  36.       }

  37.       return -1;

  38. }
复制代码





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2