IO day1作业

1.

 1 #include 
  2 #include 
  3 #include 
  4 int main(int argc, const char *argv[])
  5 {
  6         FILE *fp=fopen("usr.txt","w+");
  7         char a[10];
  8         char b[10];
  9         scanf("%s%s",a,b);
 10         fprintf(fp,"%s %s\n",a,b);
 11 
 12     return 0;                                                           
 13 }
~                                                  
1 #include 
  2 #include 
  3 #include 
  4 int main(int argc, const char *argv[])
  5 {
  6     FILE *fp1=fopen("usr.txt","a+");
  7     if(NULL == fp1)
  8     {
  9         printf("__%d__",__LINE__);perror("fp1");
 10         return -1;
 11     }
 12     char a[10];
 13     char b[10];
 14     char c[10];
 15     char d[10];
 16     char e=0;
 17     printf("请输入账号和密码:\n");
 18     scanf("%s%s",a,b);
 19     fscanf(fp1,"%s",c);
 20     fscanf(fp1,"%c",&e);
 21     fscanf(fp1,"%s",d);
 22     int f=strcmp(a,c);
 23     int g=strcmp(b,d);
 24     if(f != 0)                                                                                                            
 25     {
 26         printf("账户不存在\n");
 27     }
 28     else
 29     {
 30         if(g != 0)
 31         {
 32             printf("密码错误\n");
 33         }
 34         else
 35             printf("登录成功\n");
 36     }
 37     fclose(fp1);
 38     return 0;

2.注册

 #include 
  2 #include 
  3 #include 
  4 int main(int argc, const char *argv[])
  5 {
  6     FILE *fp=fopen("usr.txt","a+");
  7     if(NULL == fp)
  8     {
  9     printf("__%d__",__LINE__);perror("fp");
 10     }
 11     char a[10];
 12     char b[10];
 13     printf("请输入账号和密码\n");
 14     scanf("%s%s",a,b);
 15     char c[10];
 16     char d[10];
 17     char e=0;
 18     char g=0;
 19     int h=0;
 20     while(1)
 21     {                                                                                                         
 22     h=fscanf(fp,"%s",c);
 23     if(h==EOF)
 24         break;
 25     fscanf(fp,"%c",&e);
 26     fscanf(fp,"%s",d);
 27     fscanf(fp,"%c",&g);
 28     int f=strcmp(a,c);
 29     if(f == 0)
 30     {
 31      printf("账号已存在\n");return -1;
 32     }
 33     }
 34     fprintf(fp,"%s %s\n",a,b);
 35 
 36     return 0;
 37 }

3.xmid

IO day1作业_第1张图片

你可能感兴趣的:(linux)