[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:
Re: There is some thing wrong with my code
missing semicolon before for and after return -1
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 : ';'
Re: There is some thing wrong with my code
missing semicolon after -1.
Code:
if (++count>3) return -1;
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?
Re: There is some thing wrong with my code
Im sry i didnt put it in that box thing
Re: There is some thing wrong with my code
oh...you want spoon feeding....before for I meant this
Code:
char buff[PASSWORD_SIZE];
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
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
}
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
Re: There is some thing wrong with my code
Re: There is some thing wrong with my code
SWEET ty it worked an ill read my book again thanks for ur guyes help =)
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 :wave:
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.