Solved

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

Posted on 2004-04-10
9
177 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
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 and use structures in the C programming language.

738 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