Faulty loop (Yeah Me Again!)

This is a discussion on Faulty loop (Yeah Me Again!) within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> #include <string.h> struct create_account { char username[16]; char pass[16]; char conf_pass[16]; }; struct login { char username[16]; ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    39

    Talking Faulty loop (Yeah Me Again!)

    Code:
    #include <stdio.h>
    #include <string.h>
    
    struct create_account
    {
       char username[16];
       char pass[16];
       char conf_pass[16];
    };
    
    struct login
    {
       char username[16];
       char pass[16];
    };
    
    
    int main()
    {
       struct create_account c;
       struct login l;
       
       FILE *fp = NULL;
       
       char user[16];
       char pass[16];
       
       short int condition = 0;
       short int i = 0;
       short int j = 0;
       short int k = 0;
       char opt_no = 0;
       
       while(k = 0);
       {
       
          printf("\n**************ADMISSION*PROGRAM*FOR****************");
          printf("\n********************STUDENTS***********************");
       
          printf("\n\n");
        
          printf("\n1.LOG IN");
          printf("\n2.CREATE USER");
          printf("\n3.EXIT PROGRAM");
       
          printf("\nEnter Option No.:\t");
          opt_no = getchar();
       
          switch(opt_no)
          {
       
             case '1':
                   printf("\nUsername:\t");
                   scanf("%s", l.username);
                   
                   printf("\nPassword:\t");
                   scanf("%s", l.pass);
                   
                   fp = fopen("user_account.txt", "r");
                   while(fscanf(fp, "%s\t%s", user, pass) == 2)
                   {
                      if(user == l.username && pass == l.pass)
                      {
                         printf("YES.");
                      }
                   }
                   break;
                
             case '2':      
       
                   printf("\nEnter Desired Adiminisrator User Name:\t");
                   scanf("%s", c.username);
                   FILE *fp = fopen("user_account.txt", "a");
                   
                   fprintf(fp, "%s\t", c.username);
                   fprintf(fp, "\t");
       
      
                   printf("(Enter Desired Password Not Less Than 8 Characters");
                   printf("\nAnd Not More Than 16 Characters.)");
       
                   while(condition == 0) 
                   {
          
                      printf("\n\nPassword:\t\t");
                      scanf("%s", c.pass);
                      j = strlen(c.pass);
                      if(j < 8)
                      {
                         printf("\nError.Password is less than 8 characters.");
                      }
                      if(j > 16)
                      {
                         printf("\nError.Password is more than 16 characters.");
                      }
                      if(j >= 8 && j <= 16)
                      {
                         printf("Confirm Password:\t");
                         scanf("%s", c.conf_pass);
                         i = strcmp(c.pass, c.conf_pass);
             
                         if(i != 0)
                         {
                            printf("Error! Passwords do not match");
                         }
                         if(i == 0)
                         {
                            condition = 1;
                            fprintf(fp, "%s\n", c.pass);
                         }
                         
                         fclose(fp);
                         break;
                      }
            case '3':
                  k =1;
                  break;
                   }   
          }
       }   
       return 0;
    }
    i'm trying to make it so that the program returns back to the login screen after creating an account instead of exiting the program. I tried but so far not working.

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,602
    "=" is assignment, "==" is the test for equality.

    Hint: Outer loop
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    39
    changed "while(k = 0)" to "while(k == 0)" it compiles alright but it doesn't run.

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,602
    Quote Originally Posted by GolDRoger View Post
    changed "while(k = 0)" to "while(k == 0)" it compiles alright but it doesn't run.
    Didn't you notice something else on that line? Something like a spare ";"
    Devoted my life to programming...

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    39
    thanx a whole lot don't know how i could have missed that, must be getting tired.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. faulty code?
    By ceddsoboss in forum C Programming
    Replies: 12
    Last Post: 10-07-2010, 11:43 PM
  2. Faulty Program
    By Anirudh Kishan in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2009, 07:28 AM
  3. Faulty network event notification?
    By Hunter2 in forum Networking/Device Communication
    Replies: 0
    Last Post: 03-19-2004, 10:13 PM
  4. mandrake linux-faulty okay button
    By eats only heads in forum Tech Board
    Replies: 0
    Last Post: 10-25-2002, 09:37 PM
  5. faulty while loop
    By monkey_C in forum C Programming
    Replies: 8
    Last Post: 09-14-2002, 02:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21