Solved

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

Posted on 2004-04-10
9
175 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
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

Independent Software Vendors: 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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

679 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