Using illegal characters

This is a discussion on Using illegal characters within the C++ Programming forums, part of the General Programming Boards category; Hello i m new about c++ programming and i have a problem about using illegal characters. My problem is ; ...

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    2

    Question Using illegal characters

    Hello
    i m new about c++ programming and i have a problem about using illegal characters. My problem is ;

    i have to use illegal characters in my string / array but it does not let me to use it. .
    Code:
    char fordefaultname[10]=" "Name='Melisa kutar' " " // here is my problem. 
    // i can also use string it's not problem. 
    // There are 2 quotation marks.
    like here; i want to use / " Name ='Melisa Kutar' " / - in my array.

    is there anyway to do this ?
    How can i use illegal characters like " '

    i ll be glad if someone can help, any help would be appreciated..
    Thanx in advance.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Add a backslash in front of the "illegal" character, such as this:

    Code:
    printf("Hi, my name is \"Mats\"\n");
    This is almost identical to a post I wrote yesterday...

    --
    Mats

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,316
    They are 'legal', you just need to escape them (the double quotes, at least) with a backslash.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Also:

    char fordefaultname[10]=
    That declares an array of characters that are 10 characters long, then you assign a string that's longer than 10 characters.

    You shouldn't use char* or char[] for strings in C++, use std::string instead.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Cat View Post
    Also:



    That declares an array of characters that are 10 characters long, then you assign a string that's longer than 10 characters.

    You shouldn't use char* or char[] for strings in C++, use std::string instead.
    Well spotted. [Although I guess the compiler should catch such obvious cases, if it's just not too confused by the code itself].

    --
    Mats

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,174
    Quote Originally Posted by matsp View Post
    [Although I guess the compiler should catch such obvious cases, if it's just not too confused by the code itself].
    According to the letter of the standard, the compiler is not required to catch this. The result is undefined behaviour (which means anything is allowed to happen).

    In practice, good quality compilers catch some of the simple and obvious cases.

    The reason such things are undefined behaviour is that it is very difficult (and in worst cases, such as when the behaviour results from user inputs, impossible) for a compiler working alone to catch the "not simple and not obvious cases".

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by grumpy View Post
    According to the letter of the standard, the compiler is not required to catch this. The result is undefined behaviour (which means anything is allowed to happen).

    In practice, good quality compilers catch some of the simple and obvious cases.

    The reason such things are undefined behaviour is that it is very difficult (and in worst cases, such as when the behaviour results from user inputs, impossible) for a compiler working alone to catch the "not simple and not obvious cases".
    Oh, I was just saying this particular case should be caught by the compiler, not ALL cases - certainly don't expect the compiler to (generally) catch buffer overflows from user input - although both Microsoft and GCC have recently added some features to at least SOMETIMES catch those bits, but there's nothing like well-written code to prevent it in the first place - if nothing else, that is better because a compiler detected overflow will most likely just crash the application in a "sensible" way, whilst if you do the checking yourself, you can do something better that makes the application continue to work (e.g. skip the erroneous data, give an error to the user and retry, or whatever makes most sense in the particular case).

    --
    Mats

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Detecting illegal characters
    By paul_harris77 in forum C Programming
    Replies: 14
    Last Post: 02-28-2009, 01:58 PM
  2. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  4. SSH Hacker Activity!! AAHHH!!
    By Kleid-0 in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 03-06-2005, 02:53 PM
  5. Illegal Characters
    By Echidna in forum Windows Programming
    Replies: 3
    Last Post: 12-08-2002, 03:56 AM

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