Function not working

This is a discussion on Function not working within the C Programming forums, part of the General Programming Boards category; ok give me thirty minutes, I will try to fix the indents......

  1. #16
    Registered User
    Join Date
    Nov 2005
    Posts
    31
    ok give me thirty minutes, I will try to fix the indents...

  2. #17
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    parse error before else
    Of course. You need an if before an else. A for loop doesn't cut it.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #18
    Registered User
    Join Date
    Nov 2005
    Posts
    31
    alright I tabbed this girl out:
    Code:
    /*William Edward McFadden */
    
    /* Location of all files is at: */
    /* /users/williammcfadden/Documents/school/EGR 115/Final Project/    */
    
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    /* function Declarations */
       int password(FILE *);
    
        main()
       {
       
       
          FILE *Fpassword;
          FILE *Fplanes;
          FILE *Fdistout;
       
          Fpassword=fopen("/users/williammcfadden/Documents/school/EGR 115/Final Project/password.txt", "r");
          Fplanes=fopen("/users/williammcfadden/Documents/school/EGR 115/Final Project/planes.txt", "w");
          Fdistout=fopen("/users/williammcfadden/Documents/school/EGR 115/Final Project/distlog.out", "w");
       
       
       /*password function */
          password(Fpassword);
       
       
       
       
       
          printf("hello ya'll \n");
       
       
          fclose(Fpassword);
          fclose(Fplanes);
          fclose(Fdistout);
       
       }
    
    
    /************************************************************************************************/
    /************************************************************************************************/
    /************************************************************************************************/
    	
    	
    	
        int password(FILE *Fpassword)
       {
          char  NAME[50];
          int PASSWORD;
          int l;
          char* name[6];
          for(l=0; l<6; l++)
          {
             name[l]= malloc        (50);
          }
          int  password[6];
          int i;
          int h;
          int R;
          int z;
       	
       	
          for(i=0; i<6; i++)
          {
             fscanf(Fpassword, "%s",name[i]);
             fscanf(Fpassword, "%d",&(password[i]));
          }
       	
          printf("Please enter your\n");
          scanf("%s", NAME);
          printf("Please enter your password \n");
          scanf("%i", &PASSWORD);
       	
          for(h=0; h<6; h++)
          {
             if(0==strcmp(NAME, name[h]) && PASSWORD == password[h])
             {
                return 1;
             }
             else {
                printf("please enter a correct name \n");
                scanf("%s",NAME);
                printf("please enter a correct password \n");
                scanf("%i",PASSWORD);
                for(R=0; R<6; R++)
                {
                   if (0==strcmp(NAME, name[R]))
                   {
                      if (PASSWORD== password[R])
                      {
                         return 1;
                      }
                   }
                }
                {
                   printf("ONE LAST TIME BUDDY \n");
                			
                   printf("please enter your name \n");
                   scanf("%s", NAME);
                   printf("please enter your password");
                   scanf("%i", PASSWORD);
                   for(z=0; z<6; z++)
                   {
                      if( 0==strcmp(NAME, name[z]))
                      {
                         if (PASSWORD == password[z])
                         {
                            return 0;
                         }
                      }
                   }
                }
             }
          }
       }
    still wont compile or run, what am I missing?

  4. #19
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Much better indentation.

    What are your errors now?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #20
    Registered User
    Join Date
    Nov 2005
    Posts
    31
    Hey It Works!

  6. #21
    Registered User
    Join Date
    Nov 2005
    Posts
    31
    Thanks guys, I will get some help and get the main working and show you what it looks like, I am guessing that I will need an if statement
    like...
    [code]
    of value =1 then printf"tobad" close program
    value = 0, ??nothing?

    yes I will put it in c...

  7. #22
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Indentation saved the day.

    You'll have to change the thread's title now.

    One last thing. These braces aren't required:
    Code:
                for(R=0; R<6; R++)
                {
                   if (0==strcmp(NAME, name[R]))
                   {
                      if (PASSWORD== password[R])
                      {
                         return 1;
                      }
                   }
                }
                {
                   printf("ONE LAST TIME BUDDY \n");
                			
                   printf("please enter your name \n");
                   scanf("%s", NAME);
                   printf("please enter your password");
                   scanf("%i", PASSWORD);
                   for(z=0; z<6; z++)
                   {
                      if( 0==strcmp(NAME, name[z]))
                      {
                         if (PASSWORD == password[z])
                         {
                            return 0;
                         }
                      }
                   }
                }
             }
          }
       }
    You can delete them, but if you do, preserve the indentation.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #23
    Registered User
    Join Date
    Nov 2005
    Posts
    31
    it crashes when I delete them?

  9. #24
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Uh oh. It shouldn't. The program is no different without them.

    Maybe you deleted the wrong ones?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #25
    Registered User
    Join Date
    Nov 2005
    Posts
    31
    I delete the ones in red.

  11. #26
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    If it "crashes when you delete them", then your program probably won't work anyway. Put them back in and see what happens.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  12. #27
    Registered User
    Join Date
    Nov 2005
    Posts
    31
    they work when they are back in

  13. #28
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Ugh, you must have deleted the wrong ones.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  14. #29
    Registered User
    Join Date
    Nov 2005
    Posts
    31
    O well.. I am going to tried to get the if/else statement working in main then I will repost it.

  15. #30
    Registered User
    Join Date
    Nov 2005
    Posts
    31
    ok new problems...

    Here is what I have when I run the program:
    Code:
    [Session started at 2005-11-12 19:45:55 -0500.]
    Please enter your name 
    darth
    Please enter your password 
    23456
    please enter a correct name 
    Darth
    please enter a correct password 
    23456
    
    Final Project has exited due to signal 10 (SIGBUS).
    [Session started at 2005-11-12 19:49:13 -0500.]
    Please enter your name 
    darth
    Please enter your password 
    23456
    please enter a correct name 
    leia
    please enter a correct password 
    12345
    
    Final Project has exited due to signal 10 (SIGBUS).
    Here is what my code looks like:
    Code:
     /*William Edward McFadden */
    
    /* Location of all files is at: */
    /* /users/williammcfadden/Documents/school/EGR 115/Final Project/    */
    
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    /* function Declarations */
       int password(FILE *);
    
        main()
       {
       
       
          FILE *Fpassword;
          FILE *Fplanes;
          FILE *Fdistout;
       
          Fpassword=fopen("/users/williammcfadden/Documents/school/EGR 115/Final Project/password.txt", "r");
          Fplanes=fopen("/users/williammcfadden/Documents/school/EGR 115/Final Project/planes.txt", "w");
          Fdistout=fopen("/users/williammcfadden/Documents/school/EGR 115/Final Project/distlog.out", "w");
         
       /**************************************************  **********************************************/  
       /**************************************************  **********************************************/ 
       
       /*password function */
          password(Fpassword);
          if (Fpassword == 1);
          {
             printf("Sorry you really should not be using this program \n");
             system ("pause");
             exit(0);
          }
       
       
       
          printf("hello ya'll \n");
       
       
          fclose(Fpassword);
          fclose(Fplanes);
          fclose(Fdistout);
       
       }
    
    
    /**************************************************  **********************************************/
    /**************************************************  **********************************************/
    /**************************************************  **********************************************/
    /**************************************************  **********************************************/
    /**************************************************  **********************************************/
            
            
            
        int password(FILE *Fpassword)
       {
          char  NAME[50];
          int PASSWORD;
          int l;
          char* name[6];
          for(l=0; l<6; l++)
          {
             name[l]= malloc        (50);
          }
          int  password[6];
          int i;
          int h;
          int R;
          int z;
            
            
          for(i=0; i<6; i++)
          {
             fscanf(Fpassword, "%s",name[i]);
             fscanf(Fpassword, "%d",&(password[i]));
          }
            
          printf("Please enter your name \n");
          scanf("%s", NAME);
          printf("Please enter your password \n");
          scanf("%i", &PASSWORD);
            
          for(h=0; h<6; h++)
          {
             if(0==strcmp(NAME, name[h]) && PASSWORD == password[h])
             {
                return 1;
             }
             else {
                printf("please enter a correct name \n");
                scanf("%s",NAME);
                printf("please enter a correct password \n");
                scanf("%i",PASSWORD);
                for(R=0; R<6; R++)
                {
                   if (0==strcmp(NAME, name[R]))
                   {
                      if (PASSWORD== password[R])
                      {
                         return 1;
                      }
                   }
                }
                {
                   printf("ONE LAST TIME BUDDY \n");
                                    
                   printf("please enter your name \n");
                   scanf("%s", NAME);
                   printf("please enter your password");
                   scanf("%i", PASSWORD);
                   for(z=0; z<6; z++)
                   {
                      if( 0==strcmp(NAME, name[z]))
                      {
                         if (PASSWORD == password[z])
                         {
                            return 0;
                         }
                      }
                   }
                }
             }
          }
       }
    
    /**************************************************  **********************************************/
    /**************************************************  **********************************************/
    Last edited by sloopy; 11-12-2005 at 05:55 PM.

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  3. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM
  5. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM

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