Saving Line or file creation... or etc [in need of great help]

Discussion in 'Programming General' started by d great one, Aug 8, 2009.

Saving Line or file creation... or etc [in need of great help]
  1. Unread #1 - Aug 8, 2009 at 10:01 AM
  2. d great one
    Joined:
    Nov 4, 2007
    Posts:
    930
    Referrals:
    2
    Sythe Gold:
    0

    d great one Apprentice

    Saving Line or file creation... or etc [in need of great help]

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <conio.h>
    #include <stdlib.h>
    main()
    {
          char username[10];
          char pword[20];
          char cpass[20];
          int choice;
          int looper=0;
          char ynchoice[]="yes";
          char ynanswer[20];
          
          
          do{
          
          system("cls");   
          
          printf("\n[1] Display forum users\n[2] Create new user\n[3] Check username and password\n[4] Exit\n");
          printf("Enter choice: ");      
          scanf("%d",&choice);
          switch(choice)
          
          {
                         case 1:
                              printf("1: Username\n  Password");
                              getch();
                              break;
                              
                         case 2:    
                              do{                      
                              printf("\nEnter new username: ");
                              fflush(stdin);
                              gets(username);
                              printf("Enter password: ");
                              fflush(stdin);
                              gets(pword);
                              printf("Retype password: ");
                              fflush(stdin);
                              gets(cpass);                  
                              if(strcmp(pword,cpass)==0)
                              {
                                 printf("Save data? Yes or no: ");
                                 fflush(stdin);
                                 gets(ynanswer);
                                 printf("Enter new user? Yes or no: ");
                                 fflush(stdin);
                                 gets(ynanswer);                                                     
                                                        }
                                 else if(strcmp(pword,cpass)!=0)
                                 {
                                     printf("Password is not match\n");
                                     printf("Input new user? Yes or no? ");
                                     fflush(stdin);
                                     gets(ynanswer);                           
                                 }
                                 }
                              while(strcmp(ynchoice,ynanswer)==0);
                                     
                              break;
                         case 3:
                              printf("Enter username: ");
                              printf("\nEnter password: ");
                              getch();
                              break;
                         case 4:
                              return 0;
                              break;
                         default:
                                 printf("Invalid choice\nTry again");
                                 getch();
                                 break;
          
          }
          }
          while(looper==0);
    
          getch();
          
          
          
          }
    

    Ok time for another project.
    If you scan my code, you will know what I'm getting at.

    I need some help about adding and saving some lines in a separate function (like I'm going to add a function that will serve as a database for the saved user names and passwords. Although my professor already told me that saving a line in a function through input method from the user isn't possible.).
    If not possible, how about some file creation and how do I call and scan the file or something.

    Many thanks for the future help.

    Out of topic: Whew! I have 5 major projects... beats me

    EDIT: Forgot to include that I need this in C language and not c++. I did it in C++ compiler because the c compiler won't let copy and paste.
    So please help in C language library and syntax and functions. THanks.
     
< Combo Box items gathered/saving to database | C++ >

Users viewing this thread
1 guest


 
 
Adblock breaks this site