Results 1 to 13 of 13

Thread: [RESOLVED] There is some thing wrong with my code

  1. #1

    Thread Starter
    Hyperactive Member FireKnox101's Avatar
    Join Date
    Aug 2005
    Location
    Snohomish,Washington
    Posts
    301

    Resolved [RESOLVED] There is some thing wrong with my code

    Hi im using Visual Studio.net 2003 C++ and i just bought this book Called
    Hacker Disassembling Uncouvered and the first project is to type a simple code that makes a login type thing and i typed it word for word from the book and i get all these errors here is the code i typed in and the ERRORS.

    Code:
      
    // macthing the pass char wwith the corrwect car.
    // basicly making a login screen if pass is ok then go if pass is wrong the display message,
    
    #include <stdio.h>
    #include <string.h>
    
    #define PASSWORD_SIZE 100
    #define PASSWORD  "myGODpassword\n"
    // cr above is need 
    //so as not to cut it off
    // the user enterd CR
    
    int_main()
    {
    //the counter for authentication failurs
    	int count=0;
    //buffer size for the user-entered password
    	char buff[PASSWORD_SIZE],
    
    //main authentication loop
    for(;;)
    {
    	//prompt the user for pass
    	//and read it
    	printf("enter password: ");
    	fgets(&buff[0],PASSWORD_SIZE,stdin);
    
    	//matching the entered pass with the referenced one
    	if (strcmp(&buff[0],PASSWORD))
    		//"scolding if the pass is wrong
    		printf("WRONG PASSWORD\n");
    	//otherwise if pass matches then go on
    	//getting out of loop
    	else break;
    
    	//incrementing the counter of authentication failures
    	//and terminating the program if 3 attempts have been used
    	if (++count>3) return -1
    }
    //once we're here, the user has entered the right pass
    printf("Password OK\n");
    }
    Dont mind my sort hand.

    here are the errors
    -Projects\simple\simple.cpp(21): error C2059: syntax error : 'for'

    -Projects\simple\simple.cpp(21): error C2143: syntax error : missing ';' before ')'

    -Projects\simple\simple.cpp(22): error C2143: syntax error : missing ';' before '{'

    -Projects\simple\simple.cpp(34): error C2043: illegal break

    -Projects\simple\simple.cpp(39): error C2143: syntax error : missing ';' before '}'

    I hope you guys or girls can help. :wave:
    Last edited by sunburnt; Jan 8th, 2006 at 12:55 AM. Reason: code tags

    Im currently using: VB.NET 2003, And VB 2005 Express
    My Projects
    Form Them Show Keypress In App
    Simple Ping Control

  2. #2
    Addicted Member SpS's Avatar
    Join Date
    Jul 2005
    Posts
    201

    Re: There is some thing wrong with my code

    missing semicolon before for and after return -1
    #Appreciate others by rating good posts !!

    #The Software Peter Principle is in operation when unwise developers "improve" and "generalize" the software until they themselves can no longer understand it, then the project slowly dies.

    #People who are still ignorant of their ignorance are dangerous.

  3. #3

    Thread Starter
    Hyperactive Member FireKnox101's Avatar
    Join Date
    Aug 2005
    Location
    Snohomish,Washington
    Posts
    301

    Re: There is some thing wrong with my code

    ok i put the semicolon befor "for" an after -1 now i get this error

    Projects\simple\simple.cpp(21): error C2059: syntax error : ';'

    Im currently using: VB.NET 2003, And VB 2005 Express
    My Projects
    Form Them Show Keypress In App
    Simple Ping Control

  4. #4
    Lively Member
    Join Date
    Dec 2005
    Location
    middle earth
    Posts
    95

    Re: There is some thing wrong with my code

    missing semicolon after -1.

    Code:
    if (++count>3) return -1;

  5. #5

    Thread Starter
    Hyperactive Member FireKnox101's Avatar
    Join Date
    Aug 2005
    Location
    Snohomish,Washington
    Posts
    301

    Re: There is some thing wrong with my code

    Here is the code now after what sunnypalsingh told me to do and i still get 1 error

    // macthing the pass char wwith the corrwect car.
    // basicly making a login screen if pass is ok then go if pass is wrong the display message,

    #include <stdio.h>
    #include <string.h>

    #define PASSWORD_SIZE 100
    #define PASSWORD "myGODpassword\n"
    // cr above is need
    //so as not to cut it off
    // the user enterd CR

    int_main()
    {
    //the counter for authentication failurs
    int count=0;
    //buffer size for the user-entered password
    char buff[PASSWORD_SIZE],

    //main authentication loop
    ;for(;;)
    {
    //prompt the user for pass
    //and read it
    printf("enter password: ");
    fgets(&buff[0],PASSWORD_SIZE,stdin);

    //matching the entered pass with the referenced one
    if (strcmp(&buff[0],PASSWORD))
    //"scolding if the pass is wrong
    printf("WRONG PASSWORD\n");
    //otherwise if pass matches then go on
    //getting out of loop
    else break;

    //incrementing the counter of authentication failures
    //and terminating the program if 3 attempts have been used
    if (++count>3) return -1;
    }
    //once we're here, the user has entered the right pass
    printf("Password OK\n");
    }

    here is the error-

    -Projects\simple\simple.cpp(21): error C2059: syntax error : ';'

    When I click on the error it goes to ";for(;;)" I dont know what to do plzzz Help?

    Im currently using: VB.NET 2003, And VB 2005 Express
    My Projects
    Form Them Show Keypress In App
    Simple Ping Control

  6. #6

    Thread Starter
    Hyperactive Member FireKnox101's Avatar
    Join Date
    Aug 2005
    Location
    Snohomish,Washington
    Posts
    301

    Re: There is some thing wrong with my code

    Im sry i didnt put it in that box thing

    Im currently using: VB.NET 2003, And VB 2005 Express
    My Projects
    Form Them Show Keypress In App
    Simple Ping Control

  7. #7
    Addicted Member SpS's Avatar
    Join Date
    Jul 2005
    Posts
    201

    Re: There is some thing wrong with my code

    oh...you want spoon feeding....before for I meant this

    Code:
    char buff[PASSWORD_SIZE];
    #Appreciate others by rating good posts !!

    #The Software Peter Principle is in operation when unwise developers "improve" and "generalize" the software until they themselves can no longer understand it, then the project slowly dies.

    #People who are still ignorant of their ignorance are dangerous.

  8. #8

    Thread Starter
    Hyperactive Member FireKnox101's Avatar
    Join Date
    Aug 2005
    Location
    Snohomish,Washington
    Posts
    301

    Re: There is some thing wrong with my code

    But now i get these ERRORS

    -simple fatal error LNK1120: 1 unresolved externals

    -simple error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup

    -projects\simple\simple.cpp(42): warning C4715: 'int_main' : not all control paths return a value

    Im currently using: VB.NET 2003, And VB 2005 Express
    My Projects
    Form Them Show Keypress In App
    Simple Ping Control

  9. #9
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: There is some thing wrong with my code

    please try this, but it is not tested. the highlighted part is what i have either changed or added.
    Code:
    // macthing the pass char wwith the corrwect car.
    // basicly making a login screen if pass is ok then go if pass is wrong the display message,
    
    #include <stdio.h>
    #include <string.h>
    
    #define PASSWORD_SIZE 100
    #define PASSWORD  "myGODpassword\n"
    // cr above is need 
    //so as not to cut it off
    // the user enterd CR
    
    int main()  //why using underscore here??
    {
    //the counter for authentication failurs
    	int count=0;
    //buffer size for the user-entered password
    	char buff[PASSWORD_SIZE];
    
    //main authentication loop
    for(;;)
    {
    	//prompt the user for pass
    	//and read it
    	printf("enter password: ");
    	fgets(&buff[0],PASSWORD_SIZE,stdin);
    
    	//matching the entered pass with the referenced one
    	if (strcmp(&buff[0],PASSWORD) != 0) //though logically you were right
                                                               //but never take chances
    		//"scolding if the pass is wrong
    		printf("WRONG PASSWORD\n");
    	//otherwise if pass matches then go on
    	//getting out of loop
    	else break;
    
    	//incrementing the counter of authentication failures
    	//and terminating the program if 3 attempts have been used
    	if (++count>3) return -1
    }
    //once we're here, the user has entered the right pass
    printf("Password OK\n");
    return 0;  //returning the value for int main
    }
    Show Appreciation. Rate Posts.

  10. #10
    Addicted Member SpS's Avatar
    Join Date
    Jul 2005
    Posts
    201

    Re: There is some thing wrong with my code

    Do the changes as suggested by harsh...it will execute fine...and do read the chapters of your book again
    #Appreciate others by rating good posts !!

    #The Software Peter Principle is in operation when unwise developers "improve" and "generalize" the software until they themselves can no longer understand it, then the project slowly dies.

    #People who are still ignorant of their ignorance are dangerous.

  11. #11

    Thread Starter
    Hyperactive Member FireKnox101's Avatar
    Join Date
    Aug 2005
    Location
    Snohomish,Washington
    Posts
    301

    Re: There is some thing wrong with my code

    ok ty

    Im currently using: VB.NET 2003, And VB 2005 Express
    My Projects
    Form Them Show Keypress In App
    Simple Ping Control

  12. #12

    Thread Starter
    Hyperactive Member FireKnox101's Avatar
    Join Date
    Aug 2005
    Location
    Snohomish,Washington
    Posts
    301

    Re: There is some thing wrong with my code

    SWEET ty it worked an ill read my book again thanks for ur guyes help =)

    Im currently using: VB.NET 2003, And VB 2005 Express
    My Projects
    Form Them Show Keypress In App
    Simple Ping Control

  13. #13
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: There is some thing wrong with my code

    Quote Originally Posted by FireKnox101
    SWEET ty it worked an ill read my book again thanks for ur guyes help =)
    Not at all

    if we have helped you and you got your query answered, then you can help us by marking this thread resolved. just pull the *Thread Tools* menu from above the first post and click on *Mark this Thread Resolved*. ty.
    Show Appreciation. Rate Posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width