Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- typedef struct book_date{
- int day,month,year;
- }book_date;
- typedef struct book{
- int isbn;
- char *book_name;
- char *book_auteur;
- book_date publish_date;
- }book;
- typedef struct admin{
- char name[10];
- char username[30];
- char password[30];
- }admin;
- typedef struct client{
- int num_client;
- char nom[10];
- char prenom[10];
- char username[30];
- char password[30];
- }client;
- int test_user(char *user){
- FILE * fichier_client;
- client test;
- fichier_client=fopen("clients.txt","r");
- while(!feof(fichier_client)){
- fscanf(fichier_client,"%d / %s / %s / %s / %s",&test.num_client,test.nom,test.prenom,test.username,test.password);
- if(strcmp(user,test.username)==0) return 0;
- }
- return 1;
- }
- int accorder_client(char *user,char *pass){
- FILE * fichier_client;
- client test;
- fichier_client=fopen("clients.txt","r");
- while(!feof(fichier_client)){
- fscanf(fichier_client,"%d / %s / %s / %s / %s",&test.num_client,test.nom,test.prenom,test.username,test.password);
- if(strcmp(user,test.username)==0){
- if(strcmp(pass,test.password)==0) return 0;
- }
- }
- return 1;
- }
- int add_client(client clt){
- FILE * p_client;
- p_client=fopen("clients.txt","r+");
- fseek(p_client,0,SEEK_END);
- fprintf(p_client,"%d / %s / %s / %s / %s\n",clt.num_client,clt.nom,clt.prenom,clt.username,clt.password);
- fclose(p_client);
- return 0;
- }
- int main(){
- int a,i;
- client tab_client[50];
- client _client;
- printf("(1)sign up (2)sign in: ");
- scanf("%d",&a);
- getchar();
- if(a==1){
- printf("Enter Lastname: ");
- gets(_client.nom);
- printf("Enter Firstname: ");
- gets(_client.prenom);
- int try_again=1;
- while(try_again==1){
- printf("Enter Username: ");
- gets(_client.username);
- if(test_user(_client.username)==0){
- printf("Username already in use!\n");
- printf("Try Again? yes(1) no(2) : ");
- scanf("%d",&try_again);
- getchar();
- }
- else break;
- }
- if(try_again!=2){
- printf("Enter Password: ");
- gets(_client.password);
- add_client(_client);
- }
- main();
- }
- else if(a==2){
- char user_login[30],pass_login[30];
- printf("Enter Username: ");
- gets(user_login);
- if(test_user(user_login)==0){
- printf("Enter Password: ");
- gets(pass_login);
- if(accorder_client(user_login,pass_login)==0)printf("Success!\n");
- };
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement