#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 10
int main(int argc, const char *argv[])
{
	FILE* fp = fopen("./usr.txt","r");
	if(NULL == fp){
		perror("fopen: ");
		return -1;
	}
	printf("fopen success\n");
	puts("");
 
	char account[10] = "";
	char password[10] = "";
	printf("Please input account and password: ");
	scanf("%s%s",account,password);
 
	char buf[10];
	char arr[N][10];
	int i=0;
	while( fscanf(fp,"%s",buf) != EOF){
		strcpy(arr[i],buf);
		//printf("arr[%d] = %s\n",i,buf);
		i++;
	}
 
	int flag1=0,flag2=0;
	for(int j = 0 ; j < i ; j+=2){
		if(strcmp(arr[j],account) == 0)
			flag1 = 1;
	}
	for(int j = 1 ; j < i ; j+=2){
		if(strcmp(arr[j],password) == 0)
			flag2 = 1;
	}
 
	if(flag1 == 0)
		printf("account don't exit\n");
	else if(flag2 == 0 && flag1 == 1)
		printf("password wrong\n");
	else if(flag1 == 1 && flag2 == 1)
		printf("login success\n");
 
	/*for(int j = 0 ; j < i ; j++){
		printf("%s ",arr[j]);
	}*/
	//fscanf(fp,"%s",buf);
 
 
	puts("");
	if(fclose(fp) == EOF){
		perror("fclose: ");
		return -1;
	}
	printf("fclose success\n");
 
	return 0;
}