Advertisement
Ilias2019

clients

Apr 8th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.73 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. typedef struct book_date{
  5.     int day,month,year;
  6. }book_date;
  7.  
  8.  
  9. typedef struct book{
  10.     int isbn;
  11.     char *book_name;
  12.     char *book_auteur;
  13.     book_date publish_date;
  14. }book;
  15.  
  16.  
  17. typedef struct admin{
  18.     char name[10];
  19.     char username[30];
  20.     char password[30];
  21. }admin;
  22.  
  23.  
  24. typedef struct client{
  25.     int num_client;
  26.     char nom[10];
  27.     char prenom[10];
  28.     char username[30];
  29.     char password[30];
  30. }client;
  31.  
  32.  
  33. int test_user(char *user){
  34.     FILE * fichier_client;
  35.     client test;
  36.     fichier_client=fopen("clients.txt","r");
  37.         while(!feof(fichier_client)){
  38.             fscanf(fichier_client,"%d / %s / %s / %s / %s",&test.num_client,test.nom,test.prenom,test.username,test.password);
  39.             if(strcmp(user,test.username)==0) return 0;
  40.         }
  41.     return 1;
  42. }
  43.  
  44.  
  45. int accorder_client(char *user,char *pass){
  46.     FILE * fichier_client;
  47.     client test;
  48.     fichier_client=fopen("clients.txt","r");
  49.         while(!feof(fichier_client)){
  50.             fscanf(fichier_client,"%d / %s / %s / %s / %s",&test.num_client,test.nom,test.prenom,test.username,test.password);
  51.             if(strcmp(user,test.username)==0){
  52.                 if(strcmp(pass,test.password)==0) return 0;
  53.             }
  54.         }
  55.     return 1;
  56. }
  57.  
  58.  
  59. int add_client(client clt){
  60.     FILE * p_client;
  61.     p_client=fopen("clients.txt","r+");
  62.     fseek(p_client,0,SEEK_END);
  63.     fprintf(p_client,"%d / %s / %s / %s / %s\n",clt.num_client,clt.nom,clt.prenom,clt.username,clt.password);
  64.     fclose(p_client);
  65.     return 0;
  66. }
  67.  
  68.  
  69. int main(){
  70.     int a,i;
  71.     client tab_client[50];
  72.     client _client;
  73.     printf("(1)sign up (2)sign in: ");
  74.     scanf("%d",&a);
  75.     getchar();
  76.     if(a==1){
  77.         printf("Enter Lastname: ");
  78.         gets(_client.nom);
  79.         printf("Enter Firstname: ");
  80.         gets(_client.prenom);
  81.         int try_again=1;
  82.         while(try_again==1){
  83.         printf("Enter Username: ");
  84.         gets(_client.username);
  85.         if(test_user(_client.username)==0){
  86.             printf("Username already in use!\n");
  87.             printf("Try Again? yes(1) no(2) : ");
  88.             scanf("%d",&try_again);
  89.             getchar();
  90.             }
  91.         else break;
  92.         }
  93.         if(try_again!=2){
  94.             printf("Enter Password: ");
  95.             gets(_client.password);
  96.             add_client(_client);
  97.         }
  98.         main();
  99.     }
  100.     else if(a==2){
  101.         char user_login[30],pass_login[30];
  102.         printf("Enter Username: ");
  103.         gets(user_login);
  104.         if(test_user(user_login)==0){
  105.             printf("Enter Password: ");
  106.             gets(pass_login);
  107.             if(accorder_client(user_login,pass_login)==0)printf("Success!\n");
  108.         };
  109.     }
  110.     system("pause");
  111. return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement