Using illegal characters
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. .
like here; i want to use / " Name ='Melisa Kutar' " / - in my array.
char fordefaultname=" "Name='Melisa kutar' " " // here is my problem.
// i can also use string it's not problem.
// There are 2 quotation marks.
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.
Add a backslash in front of the "illegal" character, such as this:
This is almost identical to a post I wrote yesterday...
printf("Hi, my name is \"Mats\"\n");
They are 'legal', you just need to escape them (the double quotes, at least) with a backslash.
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].
Originally Posted by Cat
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).
Originally Posted by matsp
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).
Originally Posted by grumpy