Advertisement
Guest User

studentfuction.c

a guest
Jan 7th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.13 KB | None | 0 0
  1. #include "StudentFunction.h"
  2.  
  3. void CreateUser(struct User* userData)
  4. {
  5.  
  6.     printf("Choose your username ( max 64 characters and no space ): ");
  7.     scanf("%s", userData->username);
  8.  
  9.     printf("Choose your password ( max 64 characters and no space ): ");
  10.     scanf("%s", userData->password);
  11.  
  12.     printf("Your username is: %s \nYour password is: %s ", userData->username, userData->password);
  13.  
  14.     printf("\nyou account is created.");
  15.    
  16. }
  17.  
  18. int LogIn(struct User* userData, int numberOfUsers)
  19. {
  20.     char username[64];
  21.     char password[64];
  22.     int a = 1;
  23.     int check = 0;
  24.     int position;
  25.  
  26.     for( int i = 0; i < numberOfUsers; i++)
  27.     {
  28.         printf("%s\t%s\n", userData[i].username, userData[i].password);
  29.    
  30.     }
  31.  
  32.     while (a == 1)
  33.     {
  34.        
  35.  
  36.         printf("\nEnter your Username: ");
  37.         scanf("%s", &username);
  38.         getchar();
  39.         printf("\nEnter your Password: ");
  40.         scanf("%s", &password);
  41.         getchar();
  42.  
  43.         for (int i = 0; i < numberOfUsers; i++)
  44.         {
  45.  
  46.             if ((strcmp(username, userData[i].username) != 0) || strcmp(password, userData[i].password) != 0)
  47.             {
  48.             }
  49.             else
  50.             {
  51.                 check = 1;    // checkar om dom är lika med varandra.
  52.                 position = i; //vilken position användaren är på
  53.                 i = numberOfUsers;
  54.                 a = 0;
  55.                 printf("Login correct! ");
  56.             }
  57.         }
  58.     }
  59.     return position;
  60. }
  61.  
  62. void StartMenu()
  63. {
  64.     printf("\n     MENU      \n");
  65.     printf("----------------\n");
  66.  
  67.     printf("1. Log In. \n");
  68.     printf("2. Create user.\n");
  69.     printf("3. Quit program. \n");
  70. }
  71.  
  72. void MainMenu()
  73. {
  74.  
  75.     int choice = 1;
  76.     while (choice != -1)
  77.     {
  78.         char newFileName[1000];
  79.         char text[10000];
  80.         char NewPass[64];
  81.         FILE* PointerToFileText;
  82.         PointerToFileText = fopen("Text.txt", "a+");
  83.  
  84.  
  85.         printf("\n_______|MENU|__________\n");
  86.         printf("\n");
  87.  
  88.         printf("1. Input your text \n");
  89.         printf("2. Save your text to a new file \n");
  90.         printf("3. Save your text in an already existing file \n");
  91.         printf("4. Choose a file to read and present it's context \n");
  92.         printf("5. Change your password\n");
  93.         printf("6. log out \n");
  94.         printf("7. exit program \n");
  95.         printf("\nchoose a option: ");
  96.         scanf("%d", &choice);
  97.         getchar();
  98.  
  99.         switch (choice)
  100.         {
  101.         case 1:
  102.             printf("Write your text: ");
  103.             fgets(text, 1000, stdin);
  104.             printf("%s", text);
  105.  
  106.             fputs(text, PointerToFileText);
  107.             fclose(PointerToFileText);
  108.  
  109.             break;
  110.  
  111.         case 2:
  112.             printf("\n%s\n", text);
  113.  
  114.             printf("\nEnter the name of your new file: ");
  115.  
  116.             scanf("%s", newFileName);
  117.             FILE* PointerToNewFile = fopen("Text.txt", "a+");           // kommer behövas ändra när det kommer till att byta lösenord. Läser och skriver file, om det inte finns fil skapa en.
  118.             fscanf(PointerToNewFile, "%d", &newFileName);
  119.             getchar();
  120.             fputs(text, PointerToNewFile);
  121.             fclose(newFileName);
  122.  
  123.             break;
  124.         case 3:
  125.             printf("Name your already existing flie: ");
  126.  
  127.  
  128.         case 4:
  129.             printf("what file would you like to choose?: ");
  130.  
  131.         case 5:
  132.             printf("Write your new password: ");
  133.  
  134.  
  135.         case 6:
  136.             printf("You are now logged out. ");
  137.             StartMenu();
  138.             choice = -1;
  139.             break;
  140.         case 7:
  141.             exit(1);
  142.         default:
  143.             break;
  144.         }
  145.         //system("cls");
  146.     }
  147.    
  148. }
  149.  
  150. //void Geneneratekey(char* Genkey, int*  )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement