say I got a variable "char[] something = "Hello World" "
Now I want something to be empty, null. How do I do this ?
How do u declare a string to be null / empty in C ?
something.empty();
Reply:char[] something="" or char[] something=NULL. or char[] something=0.
Reply:Actually, if you are using 'C', and you just want the string to be 'empty' (i.e. still be accessable by address, but contain no characters, then you need to set the first character to '\0' (ASCII value 0) since all C strings end with a 'null' character.
Note, this is different from "NULL", which is used to initialize pointers. Now, assuming this is valid ANSI C and you used:
char something[] = "Hello World";
Then you could basically empty the string by using:
something[0] = '\0';
However, be very careful. Because you did not specify a size of the array, you will only be able to copy no more than 12 'char' values into the string (the length of "Hello World" plus its 'null' character). If you were to empty the string, then use strcpy() or other direct means to fill this string array, you would cause stack or heap corruption if you overstep that twelve char boundary.
You can do something like this:
char something[1024] = { "Hello World" };
This will ensure that you have up to 1024 characters of space (minus one for the ending null character) that you can use later to fill up with larger strings.
Reply:string is an array ends with the character \0
Friday, July 31, 2009
When using c++ i need an example code of a broken string?
like what it is for example 1,2,3,4,5ive is what i have seen in examples but i dont under stand how a string can brake and y it brakes and if possible an any 1 explain y using globle varibles is so bad
When using c++ i need an example code of a broken string?
You need to slow down.
Learn English first (no offense - or ask this question in a forum that is in your native language), then take basic class on C programming before going into C++.
When using c++ i need an example code of a broken string?
You need to slow down.
Learn English first (no offense - or ask this question in a forum that is in your native language), then take basic class on C programming before going into C++.
Simple program of stack using string for push pop functions using c?
Yes, it's simple once you learn how to do it. How are you coming along?
Simple program of stack using string for push pop functions using c?
Simple answer.
flower garden
Simple program of stack using string for push pop functions using c?
Simple answer.
flower garden
How would i split a string into a char array in c++ ?
so i have asked the used to enter a word. Let's say they type in "baby"..how would I split it so that I can get an array with array1[b], array1[a], array2[b], array3[y]..thanx in advance
How would i split a string into a char array in c++ ?
string str = "baby";
string arr [str.length];
for(int i=0; i %26lt; str.lenght; i++)
{
arr[i] = str[i];
}
Reply:http://en.allexperts.com/q/C-1040/Explod...
How would i split a string into a char array in c++ ?
string str = "baby";
string arr [str.length];
for(int i=0; i %26lt; str.lenght; i++)
{
arr[i] = str[i];
}
Reply:http://en.allexperts.com/q/C-1040/Explod...
C++ help with strings?
What are the major differences between (C strings) and the (string) class?
C++ help with strings?
The difference between living in a universe with a sun and one with eternal darkness.
string class is
easily expanable
easily copyable
has built in equality operators
has a multitude of insert, replace, etc., methods;
has iterators and revere iterators
can be passed to many stardard library algorithms
just off the top of my head.
C++ help with strings?
The difference between living in a universe with a sun and one with eternal darkness.
string class is
easily expanable
easily copyable
has built in equality operators
has a multitude of insert, replace, etc., methods;
has iterators and revere iterators
can be passed to many stardard library algorithms
just off the top of my head.
In C++, how do you print quotation marks with an string in the middle?
For example:
I want to print:
" Blah blah blah "
Blah blah blah is a string.
it won't work like this:
cout %26lt;%26lt; "Movie name: " %26lt;%26lt; setw (30) %26lt;%26lt; "\" %26lt;%26lt; movieName \"" %26lt;%26lt; endl;
In C++, how do you print quotation marks with an string in the middle?
It looks like your line should be like this:
cout %26lt;%26lt; "Movie name: " %26lt;%26lt; setw (30) %26lt;%26lt; "\"" %26lt;%26lt; movieName %26lt;%26lt; "\"" %26lt;%26lt; endl;
You need to use "\"" when you want a string that just contains a double-quote character
Reply:I thought that \" worked.
Reply:Your code not work becuse you must write:
cout %26lt;%26lt; "Movie name:" %26lt;%26lt; setw(30) %26lt;%26lt; "\"" %26lt;%26lt;moveName "\"" %26lt;%26lt;endl;
an other example:
to output : Blah "BLAH" blah
you must write:
cout%26lt;%26lt;"Blah \"BLAH\" blah";
I want to print:
" Blah blah blah "
Blah blah blah is a string.
it won't work like this:
cout %26lt;%26lt; "Movie name: " %26lt;%26lt; setw (30) %26lt;%26lt; "\" %26lt;%26lt; movieName \"" %26lt;%26lt; endl;
In C++, how do you print quotation marks with an string in the middle?
It looks like your line should be like this:
cout %26lt;%26lt; "Movie name: " %26lt;%26lt; setw (30) %26lt;%26lt; "\"" %26lt;%26lt; movieName %26lt;%26lt; "\"" %26lt;%26lt; endl;
You need to use "\"" when you want a string that just contains a double-quote character
Reply:I thought that \" worked.
Reply:Your code not work becuse you must write:
cout %26lt;%26lt; "Movie name:" %26lt;%26lt; setw(30) %26lt;%26lt; "\"" %26lt;%26lt;moveName "\"" %26lt;%26lt;endl;
an other example:
to output : Blah "BLAH" blah
you must write:
cout%26lt;%26lt;"Blah \"BLAH\" blah";
Subscribe to:
Posts (Atom)