C Escape sequences

This is a discussion on C Escape sequences within the C Programming forums, part of the General Programming Boards category; Apart from \n and \t escape sequnces, which escape sequences can be written into code and be "invisible" to the ...

  1. #1
    Registered User
    Join Date
    Jul 2009
    Location
    Croatia
    Posts
    272

    C Escape sequences

    Apart from \n and \t escape sequnces, which escape sequences can be written into code and be "invisible" to the user?

    For example;
    char a='
    '

    In between the ' ' is a \n when the program reads it. How about other Escapes? Can i find them on the keyboard?

    For example \r, \v etc...

    The reason im asking this is because im writing a syntax checker in C and i want to know which escape sequences count more then 1 blank, and are they all writtable by keyboard.
    Last edited by Tool; 11-20-2009 at 08:10 AM.

  2. #2
    Epy
    Epy is offline
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    960

  3. #3
    Registered User
    Join Date
    Jul 2009
    Location
    Croatia
    Posts
    272
    Yeah. But i mean can you for example, input a carriage return from the keyboard, or an alert bell into the program.

    Like getchar(); and it gets a alert bell. Is it possible? How?
    Last edited by Tool; 11-20-2009 at 08:15 AM.

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    2,027
    Principally any valid ascii character can be written directly. C is defined to be written in ascii, and any valid ascii character can be used in a string.

    Editors may prevent the use of non printable characters, however. But some might not, and one can always use a hex editor.

    Also, some compilers may accept nonascii C source code, and would presumably allow characters from the full character set to be use. This is useful for internalization. Normally such characters would have to be escaped with hex or octal character codes.
    Last edited by King Mir; 11-20-2009 at 08:18 AM.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  5. #5
    Registered User
    Join Date
    Jul 2009
    Location
    Croatia
    Posts
    272
    So if i want to input a horizontal tab into my program with getchar(), ill press tab on the keyboard.
    If i want to input an alert bell, what then?

    Will it work if i try printing that input out?

  6. #6
    Registered User
    Join Date
    Jul 2009
    Location
    Croatia
    Posts
    272
    Or let me rephrase myself.

    I have a standard laptop keyboard.

    Do most of the standard keyboards involve:
    --alert bell
    --formfeed
    --carriage return
    --vertical tab( space? )

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    2,027
    It might work on Windows if you hold Alt and type 007 in the number pad on windows.

    You can still create source files with non printable characters with commands. You may then be able to copy+paste them. Echo -e on Linux can be used to output escaped characters. And of course you can write a c program that writes unprintable characters to a file.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  8. #8
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Why not just treat all non-printing characters as a single blank? Except for tab, of course.

    The whole thing is arbitrary anyway. Consider "vertical tab", which supposedly moves the cursor vertically. This is basically an imaginary number of blanks, since it's moving along a perpendicular axis. And imaginary blanks make my head hurt.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  9. #9
    Registered User
    Join Date
    Jul 2009
    Location
    Croatia
    Posts
    272
    Its not arbitrary to me though;

    im writing a syntax checker. But ill take your advice, and take all non-printing characters as a single blank except newline and tab. I suppose only \n and \t escape sequences take more then 1 space in the code, right? (\n doesnt, but its a special case, very important for syntax checking).

    Example:
    char a='<tab' // woop constant error! if you dont add the if(c=='\t' || c=='\n') in your debuger.
    char b='<newline> //again error, constant missing terminating char
    Last edited by Tool; 11-20-2009 at 07:09 PM.

  10. #10
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Quote Originally Posted by Tool View Post
    Its not arbitrary to me though;

    im writing a syntax checker. But ill take your advice, and take all non-printing characters as a single blank except newline and tab. I suppose only \n and \t escape sequences take more then 1 space in the code, right? (\n doesnt, but its a special case, very important for syntax checking).

    Example:
    char a='<tab' // woop constant error! if you dont add the if(c=='\t' || c=='\n') in your debuger.
    char b='<newline> //again error, constant missing terminating char
    I guess I don't understand how this relates to "how many blanks" a given character represents. What do blanks have to do with syntactic correctness?
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  11. #11
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by Tool View Post
    Its not arbitrary to me though;

    im writing a syntax checker. But ill take your advice, and take all non-printing characters as a single blank except newline and tab. I suppose only \n and \t escape sequences take more then 1 space in the code, right? (\n doesnt, but its a special case, very important for syntax checking).

    Example:
    char a='<tab' // woop constant error! if you dont add the if(c=='\t' || c=='\n') in your debuger.
    char b='<newline> //again error, constant missing terminating char
    Just use the ascii number, and go on. Defines can help, also:
    Code:
    #define ESC 27
    #define SPACE 32
    
    //etc.
    I don't understand the "<" and ">" in your code, and the "newline" and "tab", are just wrong, of course. Number of blanks? WTF??

    D/L an ascii table and use it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Interpreting literal escape sequences from a file...
    By Sebastiani in forum C++ Programming
    Replies: 1
    Last Post: 07-08-2003, 02:00 PM
  2. Using escape sequences as user inputs
    By musayume in forum C Programming
    Replies: 4
    Last Post: 12-11-2001, 08:35 AM
  3. ANSI Escape Sequences OR Scan of keyboard
    By Samppa in forum Linux Programming
    Replies: 3
    Last Post: 10-24-2001, 12:15 PM
  4. Escape sequences in VC++
    By emilyh in forum Windows Programming
    Replies: 7
    Last Post: 09-26-2001, 07:02 AM
  5. Escape Sequences
    By Me-Again-Again in forum C Programming
    Replies: 3
    Last Post: 09-05-2001, 06:24 AM

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