题目描述
小平在五一期间趁学弟不在,每天在实验室过度看视(电)频(影),患了健忘症,以前的很多事情都记不起来了。但小平以前有个习惯,总喜欢把自己在各种系统的密码记录在一个文本文件ping.dic中,文件内容包含每个系统的名称,用户名和密码。
文件包含若干行,前3行的信息如下,
ytoj 201358503114 xiaop
163 xiaoping movie
qq 944051010 Smallping
现请帮助小平编程实现查询指定系统的用户名和密码。
输入
要查询的系统名称
输出
输出对应系统的用户名和密码,如果没有所要查询的系统,不需要输出任何信息。
样例输入
qq
样例输出
user 944051010
password Smallping
参考代码
#include<stdio.h>
#include<string.h>
struct student
{
char os[20];
char user[20];
char mima[20];
}
;
int main()
{
struct student std[100];
char str[20];
int i=0;
FILE *fp;
fp=fopen("ping.dic","r");
for (i=0;i<=99;i++)
{
fscanf(fp,"%s%s%s",std[i].os,std[i].user,std[i].mima);
}
fclose(fp);
scanf("%s",str);
for (i=0;i<=99;i++)
{
if(strcmp(str,std[i].os)==0)
printf("user %snpassword %sn",std[i].user,std[i].mima);
}
return 0;
}
解析
暂无