?
Solved

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

Posted on 2004-04-10
9
Medium Priority
?
180 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 

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 120 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Suggested Courses

801 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