Reverse Engineering RET Homepage RET Members Reverse Engineering Projects Reverse Engineering Papers Reversing Challenges Reverser Tools RET Re-Search Engine Reverse Engineering Forum Reverse Engineering Links

Go Back   Reverse Engineering Team Board > Reverse Engineering Board > Reverse Code Engineering
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
  #1  
Old 09-05-2008, 09:14 AM
jackall jackall is offline
Junior Member
 
Join Date: Sep 2008
Posts: 2
Default #define password "abc\n"

My acquaintance with any language or coding is almost imaginary. This following code by an eminent personality used in his book, got on my meager imagination and made me feel again my inadequacies in this ground.

The level of my comprehensibility is ridiculed by these five characters “abc\n”.

Code:
#include<stdio.h>
#include<string.h>
#define Length  100
#define password  "abc\n"

int main()
{
    char buff[Length];
    int count=0;
    for(;;)
        {
        printf("Enter password\n");
        fgets(&buff[0] , Length ,stdin);
        if(strcmp(&buff[0], password))
        printf("\nWRONG...\n");
        else break;
        if(++count>2)
        return -1;
        }
        printf("CORRECT");
}
When prompted, i enter the password abc\n, I get WRONG message. If i remove the \n from #define password “abc”, again i get WRONG message no matter whatever the input is?

Of course the code gives CORRECT response when the string “abc” is entered.
Could i get a little explanation on this (#define password “abc\n”) ?

Thank you...

Last edited by jackall : 09-05-2008 at 09:18 AM.
Reply With Quote
  #2  
Old 09-05-2008, 10:15 AM
Git Git is offline
Super Moderator
 
Join Date: Oct 2007
Location: Torino
Posts: 1,797
Default

\n is C language for carriage return/enter. If you read a book on C you will learn that very early, and you clearly need to read a book on C !

Git
Reply With Quote
  #3  
Old 09-06-2008, 06:22 AM
kodyazan kodyazan is offline
Senior Member
 
Join Date: Jul 2008
Posts: 60
Default

if you only want "abc" without enter (\n), you may use
gets(&buff[0]);
instead of
fgets(&buff[0] , Length ,stdin);

--Editing--
And be carefull when using gets().

If someone enters 500 characters, your program above, will -mostly- crash.
(gets() doesn't check buffer overflow. fgets() is safer).

Last edited by kodyazan : 09-06-2008 at 05:53 PM.
Reply With Quote
  #4  
Old 09-06-2008, 01:19 PM
jackall jackall is offline
Junior Member
 
Join Date: Sep 2008
Posts: 2
Default

Thank you …kodyazan
Yes...i will try to understand in depth what you have explained...

Regards…
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump





Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.