Suppose I have a char* elem that is supposed to hold a char**, such that elem[0] = char**, elem[1...m]= <more chars>. Is there a way I can put a null ptr within char* elem? When I try to set elem = NULL, it gives me a type error because NULL is an int.
Any help would be greatly appreciated!
...
Possible Duplicate:
C++ char* vs std::string
Is there any advantage to using char*'s instead of std::string?
I know char*'s are usually defined on the stack, so we know exactly how much memory we'll use, is this actually a good argument for their use? Or is std::string better in every way?
...
I'm pretty well versed in C#, but I decided it would be a good idea to learn C++ as well. The only thing I can't figure out is chars. I know you can use the string lib but I also want to figure out chars.
I know you can set a char with a limit like this:
#include <iostream>
using namespace std;
int main()
{
char c[128] = "limited ...
Hi,
I need to store a certain amount of data in the "char *" in C++, because I want to avoid std::string to run out of memory, when exceeding max_size(). But the data comes in data blocks from the network so I need to use reallocation every time I get the data block. Is there any elegant solution for char * reallocation and concatenatio...
I've been playing with pointers to better understand them and I came across something I think I should be able to do, but can't sort out how. The code below works fine - I can output "a", "dog", "socks", and "pants" - but what if I wanted to just output the 'o' from "socks"? How would I do that?
char *mars[4] = { "a", "dog", "sock", "...
class MyClass
{
public:
void setVar(const char *str);
private:
std::string mStr;
int maxLength; //we only store string up to this length
};
What's the best approach to implement setVar when the external code is quite likely to pass in NULL for an empty string (and cannot be changed)? I currently do something a bit like:
void M...
I'm working in a C, and C++ program. We used to be compiling without the make-strings-writable option. But that was getting a bunch of warnings, so I turned it off.
Then I got a whole bunch of errors of the form "Cannot convert const char* to char* in argmuent 3 of function foo". So, I went through and made a whole lot of changes to fix...
I have this class, with the atribute 'word'
class Node {
char *word;
Inside the Node constructor, I do this asignation:
word = new char[strlen(someword)];
In the destructor of the Node class, I try to delete the contents pointed by word:
delete []word;
I obtain the next message after executing the programs:
"Heap block ...
Hi Guys,
I am using TortiseSVN and we have a problem when we exporting etc because subversion errors. The path has a character limit 255 - so I am not sure if this is the problem [I think it is in Win7 x-64 bit]
How do I fix this ? i.e. allow paths for >255 characters ?
...
public static void ejemplosString(String palabra){
char[] letras = palabra.toCharArray();
int contadorVocales = 0;
for (int i = 0; i < letras.length; i++) {
if (char[i] == 'a') {
contadorVocales++;
}
if (char[i] == "e") {
...
Hi,
I need a solution for quite complex problem. Exactly, I need to calculate the number of rectangles that can be placed inside letter/character with given size, considering that all rectangles are the same size, but it(the size) and the letter/character(of some regular specific font) itself can be changed by user(this will be used as w...
Hi..
I have get error with the following code and i can't figure it out.
char name[]="tolgahan"
char result[100]="";
strncat(result,name[1],1);
I guess, i need to convert name[1] to string format but i don't now how can i do that.
Please help me.
Best regards.
...
i intend to fill a char-pointer array successively in a for-loop. the content to fill in is a integer so i need to cast. but i didn't get the result i want to..
for (i=0;i<max0;i++){
sprintf(buf, "%d", content[i]);
}
sprintf replaces the hole buf, but i want to append.
for (i=0;i<max0;i++){
buf[i]=(char) contint[i]
}
but th...
Hi everyone,
I have an object called Student, and it has studentName, studentId, studentAddress, etc.
For the studentId, i have to generate random string consist of seven numeric charaters,
eg.
studentId = getRandomId();
studentId = "1234567" <-- from the random generator.
and i have to make sure that there is no duplicate id.
than...
I was working on Project Euler 40, and was a bit bothered that there was no int.Parse(char). Not a big deal, but I did some asking around and someone suggested char.GetNumericValue. GetNumericValue seems like a very odd method to me:
Takes in a char as a parameter and returns...a double?
Returns -1.0 if the char is not '0' through '9...
For my answer in this question I have to compare two characters. I thought that the normal char.CompareTo() method would allow me to specify a CultureInfo, but that's not the case.
So my question is: How can I compare two characters and specify a CultureInfo for the comparison?
...
Edit: Thank you all very much for your help. Now I feel that I'm really stupid and I am so sorry to waste your time. After implementing James Hopkin' suggestion, I still get the warnings of "invalid name 'null'", which is much better than those weird characters. Then, I went back and read the library document again, and it turns out that...
#include <iostream>
using namespace std;
typedef struct
{
char streetName[5];
} RECORD;
int main()
{
RECORD r;
cin >> r.streetName;
cout << r.streetName << endl;
}
When I run this program, if I enter in more than 5 characters, the output will show the whole string I entered. It does not truncate at 5 characters. Why...
I want to copy a string into a char array, and not overrun the buffer.
So if I have a char array of size 5, then I want to copy a maximum of 5 bytes from a string into it.
what's the code to do that?
...
If I declare a function like this:
string hash (char* key)
then any change I make to key will also change it's value when the function exits, correct?
I want to make a copy of it in the function so that I can safely change it without changing the original value.
I tried this, but it doesn't work.
char temp = key;
How can it be do...