Solved

Login, Help me 2 more day to pass up to sch

Posted on 2004-04-10
9
171 Views
Last Modified: 2010-04-15
i dont know whats is wrong.
I save the file as the username but when the user key in the username, the loop will not go to the /*if loop*/ when the key in username is correct.
 
  This is my LOGIN CODE
   printf("\n\t\tEnter username: ");
   gets(user);
   filename = user;
   if((fs = fopen(filename, "r"))==NULL)
   {          
              system("cls");
              printf("\n\n\n\t\t\tUsername not Registered!!
                        \n\n\t\t\tPlease register Yourself.\n\n\t\t\t");
              system("pause");
              main();
   }
   else
   {
               verif();
               fclose(fs);
                                     
   }

      verif() //This is only a part of it, what is wrong
         printf("\n\t\tPlease enter your username: ");
         gets(user);
         filename = user;
         fs = fopen(filename, "w");
         for(x=0; x<8; x=x+1) //This is where i save my password
          {
                fprintf(fs,"%c", pw[x]);
          }
          fclose(fs);
0
Comment
Question by:HonAlan
  • 6
  • 2
9 Comments
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10797371
do
strcpy(filename,user);
instead of
filename=user;
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10797377
>for(x=0; x<8; x=x+1) //This is where i save my password

for(x=0; x<strlen(user); x=x+1)
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10797388
>for(x=0; x<strlen(user); x=x+1)
should be
for(x=0; x<strlen(pw); x=x+1)
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10797412
>I save the file as the username but when the user key in the username, the loop will not >go to the /*if loop*/ when the key in username is correct.
//if the file does not exist then executes the if portion,so if user exists it will not execute this
  if((fs = fopen(filename, "r"))==NULL)
  {          
             system("cls");
             printf("\n\n\n\t\t\tUsername not Registered!!
                       \n\n\t\t\tPlease register Yourself.\n\n\t\t\t");
             system("pause");
             main();//why this call???
  }
  else //else this part
  {
              verif();
              fclose(fs);
                                     
  }
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:HonAlan
ID: 10797496
i have solve the problem myself thanks. I have alot of void function but how do i take the username in the other function and put the username into another function. No global variable are allowed. global function can.

         void LOGIN
          gets(user);
          filename = user
          fs = fopen(filename, "r");

        void changingPassword
           //what should i put here
           fs = fopen(filename, "r");
0
 

Expert Comment

by:ramavorray
ID: 10798355
Dlete the old file name by asking user to supply his old password along with his new password.
delete a file by suing system() function and dos command to delete a file
Create a new filename
use fopen("<filename>", "w");

Hope this helps
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10799723
use the remove fn. to remove a file.

remove("filename.txt");

and for creating a new file with the changed password,use the write mode(as ramavorray pointed out)
0
 

Author Comment

by:HonAlan
ID: 10800682
that is not what i meant.
   void LOGIN
          gets(user); //In login, i must get the username first
          filename = user  //then filename = user
          fs = fopen(filename, "r"); //then read filename as
                                                 the username

    void changingPassword
     //if i want to get the username  that the user key in in the void LOGIN() but i dont want to 'gets(user);' here again to get the username.
 
           //what should i put here to so that filename = ?
           fs = fopen(filename, "r"); /*so that i can read the same file*/
         
0
 
LVL 9

Accepted Solution

by:
ankuratvb earned 30 total points
ID: 10800742
Pass the filename as an argument to the function changingpassword()

void changingpassword(char *filename)
{
  fs = fopen(filename, "r"); /*so that i can read the same file*/
}


call it using:
void LOGIN()
         gets(user); //In login, i must get the username first
         filename = user  //then filename = user
         fs = fopen(filename, "r"); //then read filename as
                                                the username
         changingpassword(filename);
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now