Advertisement
kk258966

c++ 練習二

Jun 11th, 2014
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int i,count,count01;
  6. void check();
  7.  
  8. int main(void)
  9. {  
  10.     int i;
  11.     char str[100];
  12.     printf("請輸入你的名字\n");
  13.     scanf("%s",&str);
  14.     printf("你輸入的名字是:");
  15.     for(i=0; i<strlen(str); i++)
  16.     printf("%c",str);
  17.     printf("\n======================\n\n");
  18.    
  19.     FILE *read;
  20.     read = fopen("student.txt","r");
  21.     char string[100];
  22.     int flag;
  23.     count = 0;
  24.            while (fgets (string, 65535,read))   //65535 緩衝  
  25.        {  
  26.            count = count+1;
  27.            flag = 0;  
  28.           for(i=0; i<strlen(string); i++)
  29.           {                  
  30.           if(string!='\n')
  31.           {
  32.               if(str!=string)
  33.               {
  34.                  flag = 1;
  35.                  break;
  36.               }
  37.               //printf("%c",string);  
  38.           }
  39.            //printf("\n");
  40.            
  41.          }
  42.          if (flag==0)
  43.             break;    
  44.        }
  45.           fclose(read);
  46.          
  47.       if(flag==0)
  48.       {
  49.          printf("驗證通過");
  50.          check();
  51.       }
  52.       else
  53.       {
  54.           printf("驗證不通過");
  55.       }
  56.    
  57.    
  58.     system("pause");
  59.     return 0;
  60. }
  61.  
  62. void check()
  63. {
  64.     printf("\n**讀成績檔**\n\n");
  65.     FILE *read01;
  66.     read01 = fopen("score.txt","r");
  67.     char string[100];
  68.     count01 = 0;
  69. while (fgets (string, 65535,read01))
  70. {
  71.       count01 = count01 + 1;
  72.       if(count01==count)
  73.       printf("%s\n",string);
  74.       }
  75.      
  76.       fclose(read01);
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement