I have a code here. I am using malloc to allocate memory to my struct. One member of this struct is assigned a string using StrDup inside a while loop though other members dont have to change their values. Now, as I am using StrDup, I have to clean…
What does the error mean? I just need to return the value I get from the redis command.
int getReply(char* result)
{
redisContext *c;
redisReply *reply;
c = redisConnect((char*)"127.0.0.2", 6379);
reply = redisCommand(c,"GET %s",…
I'm fairly new to pointers, and void pointers is still black art to me.
In the following code I get a segfault when tmp->item = strdup(item);
I'm not sure how to fix.
int springmap_add(SpringMap *sm, char *key, void *item) {
SpringMap *tmp =…
when input has "|" the string splits normally, when str does not have "|" it seg faults
char **cmds;
if (strchr(input, '|'))
cmds = split(input,'|');
else
cmds[0] = strdup(input);
I'm trying to build OCRmyPDF under Cygwin and have run into a brick
wall. While I've been a developer my entire career, I've worked
mostly in Java and have little knowledge of Python internals and C++.
The problem might be obvious to an expert in…
I have a question about duplicating a 0-terminated string:
const char * str = "Hello World !";
size_t getSize = strlen(str);
char * temp = new char[getSize + 1];
... i know i can use this function
memcpy(temp, str, getSize);
but i want to use my…
i would like to know if strdup adds a '\0' at the end of the new array if the src array does not contain one ?
let's assume we have an array containing "hello" allocated by this kind of malloc
malloc(sizeof(char) * 5);
so 5 bytes for 5…
I am trying to save csv data in an array for use in other functions. I understand that strdup is good for this, but am unsure how to make it work for my situation. Any help is appreciated!
The data is stored in a struct:
typedef struct current{
…
I call strdup to duplicate the 'card' string in set_device( devname )
set_device( devname )
and then I use 'card' to open mixer:
devname is in format hw:0/Mic
static char *card, *channel;
static snd_mixer_t *handle = NULL;
static snd_mixer_elem_t…
My main intention is to pass a pointer to a structure, to a function, which will allocate memory and fill all its values. After returning back i will print it on screen.
Structure looks like this.
struct isolock{
char *name;
unsigned int…
i have to do my function always.I can not using standart library.
My_cpy , my_len and my_strdup function in here. Please check it for me. I think it is easy but i have a problem about this function. I showed the error at the end of the page. I think…
I have tried to find an answer but couldn't see anything straight forward.
How do I free the allocated memory in the next snippet code:
const char* attStr = strdup(OtherCharStr);
string str(attStr, strlen(attStr));
delete str; //???