What does this mean?

This is a discussion on What does this mean? within the C Programming forums, part of the General Programming Boards category; my instructor wants us to write a encryption program and gave us the following code. I know what it does, ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    23

    What does this mean?

    my instructor wants us to write a encryption program and gave us the following code. I know what it does, but what i would like to know is how does it work?would some explain it?


    Code:
    void getMessage(char*p){
    	char*s = p;
    
    	printf("Enter a message to be encryptes -> ");
    	while((*s=getch())!="\n"){
    		if(*s == '\b'){
    			s--;
    			s=(s<p) ? p : (printf("\b \b"),s);
    		}
    		else {
    			printf("*");
    			s++;
    		}
    	}
    	*s='\0\;
    }
    btw, does '\b' mean a [space]?

    many thanks to any help!
    Last edited by lucy; 10-10-2001 at 08:52 PM.

  2. #2
    Ian
    Ian is offline
    Registered User
    Join Date
    Oct 2001
    Posts
    21

    frowny face

    uh... there's a frowny face in your code man ):

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    23
    opps the face was an accident

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    That frowny face is what happens when you do :( in code. I really wish code would disable smileys...

    '\b' is the standard character for backspace.

    So, pretty much what the program does is it takes the pointer and if the user types in something not a backspace, then it stores it in the string, advances the pointer, and prints a '*'.

    If the user does type in a backspace, it decrements s, checks to see if this would be a buffer underflow (s < p)? and if it is, then it just keeps s pointing to the beginning of the buffer (s = p), and otherwise it actually keeps s decremented, and prints a backspace character (ie, gobbles up one of the '*'s).

Popular pages Recent additions subscribe to a feed

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