|
-
Jan 7th, 2006, 11:01 PM
#1
Thread Starter
Hyperactive Member
[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
-
Jan 7th, 2006, 11:31 PM
#2
Addicted Member
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.
-
Jan 7th, 2006, 11:58 PM
#3
Thread Starter
Hyperactive Member
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 : ';'
-
Jan 8th, 2006, 12:58 AM
#4
Lively Member
Re: There is some thing wrong with my code
missing semicolon after -1.
Code:
if (++count>3) return -1;
-
Jan 8th, 2006, 01:09 AM
#5
Thread Starter
Hyperactive Member
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?
-
Jan 8th, 2006, 01:12 AM
#6
Thread Starter
Hyperactive Member
Re: There is some thing wrong with my code
Im sry i didnt put it in that box thing
-
Jan 8th, 2006, 02:11 AM
#7
Addicted Member
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.
-
Jan 8th, 2006, 04:06 AM
#8
Thread Starter
Hyperactive Member
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
-
Jan 8th, 2006, 04:28 AM
#9
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
}
-
Jan 8th, 2006, 04:34 AM
#10
Addicted Member
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.
-
Jan 8th, 2006, 04:40 AM
#11
Thread Starter
Hyperactive Member
Re: There is some thing wrong with my code
-
Jan 8th, 2006, 04:42 AM
#12
Thread Starter
Hyperactive Member
Re: There is some thing wrong with my code
SWEET ty it worked an ill read my book again thanks for ur guyes help =)
-
Jan 8th, 2006, 12:41 PM
#13
Re: There is some thing wrong with my code
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|