标准IO函数

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(int argc,const char *argv[])
{
    if(argc<3){
        printf("请输入要拷贝的文件名\n");
        return -1;
    }
    FILE *fp1=fopen(argv[1],"r");
    if(NULL == fp1){
        perror("fopen");
        return -1;
    }
    FILE *fp2=fopen(argv[2],"w");
    if(NULL == fp2){
        perror("fopen");
        return -1;
    }
    int count=0;
    int num=0;
    char c;
    while(1){
        c = fgetc(fp1);
        if(c<0)
            break;
        if(c=='\n')
            num++;
        count++;
        fputc(c,fp2);
    }

    printf("文件大小:%d\n",count);
    printf("文件行数:%d\n",num-1);
    fclose(fp1);
    fclose(fp2);
    return 0;
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct{
    char id[20];
    char password[20];
}people;

int main(int argc,const char *argv[])
{
    people p = {0};
    char name[20],key[20];
    printf("input id>");
    scanf("%s",name);
    printf("input password>");
    scanf("%s",key);
    //打开存储账户密码的文件
    FILE * fp = fopen("./usr.txt","r");
    if(NULL == fp){
        perror("fopen");
        return -1;
    }
    int count=0,num=0;
    //读取文件内信息
    while(1){
        int num1 = fscanf(fp,"%s",p.id);
        if(num1 < 0)
            break;
        int num2 = fscanf(fp,"%s",p.password);
        if(num2 < 0)
            break;
        //对账户名进行比较
        if(strcmp(p.id,name)==0){
            count++;//存在账户,则计数器num加一
            //对密码进行比较
            if(strcmp(p.password,key)==0){
                num++;//存在密码,则计数器num加一
                printf("登录成功\n");
                break;//成功登录则直接退出循环
            }
        }
        
        bzero(p.id,0);
        bzero(p.password,0);
    }

    if(count==0)
        printf("账户不存在\n");
    else if(num==0)
        printf("密码错误\n");

    fclose(fp);
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值