|
I assume when I do char* = "string" its the same thing as char* = new char[6] . I believe these strings are created on the heap instead of the stack. So do I need to destroy them or free their memory when I'm done using them or do they get destroyed by...
Started by Daud on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
I assume when I do char* = "string" its the same thing as char* = new char[6....
Should read:
const char* c = "string";
And a new char array should be delete d just like any other need to delete [] your second example.
|
|
Yo!
I'm trying to copy a few chars from a char[] to a char*. I just want the chars from index 6 to (message length - 9).
Maybe the code example will explain my problem more:
char buffer[512] = "GET /testfile.htm HTTP/1.0"; char* filename; // I want *filename...
Started by petsson on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
char buffer[512] = "GET /testfile.htm HTTP/1.0"; char filename[512]; ....
The next problem is your offset.
Either just declare
char filename[512];
or malloc some memory for the new name (and don't a buffer for filename .
At anything.
|
|
Someone here recently pointed out to me in a piece of code of mine I am using
char* name = malloc(256*sizeof(char)); // more code free(name);
I was under the impression that this way of setting up an array was identical to using
char name[256];
and that...
Started by faceless1_14 on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
It's useful to recall the whole "declared....
}
I was rather surprised in answers.
Also, sizeof(char) is always 1 according,
// file foo.c char name[256]; int foo() { // do something here.
Running out of stack or doing heavily recursive stuff.
|
Ask your Facebook Friends
|
I have a old program in which some library function is used and i dont have that library.
So I am writing that program using libraries of c++. In that old code some function is there which is called like this
*string = newstrdup("Some string goes here...
Started by Chaithra on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
In a different way:
int redup(char **s1, const char *s2) { size_t len, size; if (s2 == NULL) return -1; len strdup :
char * newstrdup(char const* str) { char *c = new char[std::strlen(str) + 1]; std::strcpy(c....
|
|
Is there a function in c that will return the index of a char in a char array?
For example something like:
char values[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char find = 'E'; int index = findInedexOf( values, find );
Started by Josh Curren on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
For example:
char values[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char find = 'E'; const char *ptr = strchr(values, find); if(ptr) { int index = ptr - values; // do) from the original char....
The offset with the starting pointer.
|
|
How can I convert a char to a char* in c#?
I'm initializeing a String object like this:
String test=new String('c');
and I'm getting this error:
Argument '1': cannot convert from 'char' to 'char*'
Started by Uince on
, 15 posts
by 15 people.
Answer Snippets (Read the full thread at stackoverflow):
You can simply use:
String test="c";
If you have a specific need to convert a char variable character, you can use the following:
String test = new String(new char[] { 'c' });
string myString1 = new string(new char....
To store in it.
|
|
Hi can any body tell me how to conver const char* to char*?
get_error_from_header(void *ptr, size_t size, size_t nmemb, void *data) { ErrorMsg *error = (ErrorMsg *)data; char* err = strstr((const char *)ptr,"550"); //error cannot convert const char** ...
Started by Cute on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
You don't appear to use err in the rest of that function, so why bother... .
Can't you just do:
char* err = strstr((char *)ptr,"550");
The error is because if you pass in a const char* to strstr you get one out (because of the overload).
|
|
Hi all, my problem is in convert a char to string i have to pass to strcat() a char to append to a string, how can i do? thanks!
#include <stdio.h> #include <string.h> char *asd(char* in, char *out){ while(*in){ strcat(out, *in); // <--...
Started by frx08 on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Giving char a[200] = "" will give you a[0;stdio.h> #include <string.h> char *asd(char* in, char *out) { /* It is incorrect to pass of the array to strcat */ ....
Of characters which is terminated by a '\0' character).
|
|
I have:
unsigned char *foo(); std::string str; str.append(static_cast<const char*>(foo()));
The error: invalid static_cast from type ‘unsigned char*’ to type ‘const char*’
What's the correct way to cast here in C++ style?
Started by Jack on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Try reinterpret_cast
usigned char *foo(); std::string str; str.append(reinterpret_cast<const char*>(foo()));
char * and const unsigned char char* to a non const type you'....
Between are unrelated to each other.
|
|
Possible Duplicate:
C - Difference between “char var[]” and “char *var” ?
What is the difference between Char a[ ]=”string” and char *a=”String” ?
one more thing,
Char *a="String" ;
Here we are using Pointer 'a' without allocating dynamic memory, is it...
Started by SIVA on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
The allocation for you as if you have declared Char a[6+1] = "String";
In the second you to correct, the second should look like:
int size = strlen("String") + 1; char *a = (char *) malloc it to point to memory in the executable ....
|