In the below code, we get a pointer from strdup(source) and we store it in a pointer named target.
Now, when we print the string using pointer, we don't add * at the beginning of the pointer: why is it so? As I studied whenever we want to…
I have a linked list in which I am trying to free a char* which I used strdup for.
These are the methods I have for adding a node into my list:
node* add_first(char* name, node* head) {
node* new_node;
new_node =…
I am using strdup to duplicated the value inside command. I also free it at the end of my loop to make sure I don't have anything leaking but valgrind seems to disagree with me and says that what is allocated with this strdup is leaking. Any…
I have created an array of structure Human which consists of char *name.
I use function like this:
Human *createHuman(char *name){
Human *h = malloc(sizeof(Human));
h->name = strdup(name);
return h;
}
I have tested this function, it…
I'm trying to store file names in an array. The array is in a struct, and I want to store the names of files found in a directory in the array. However, the process that I'm using to store the names seems to be corrupting 2 or 3 of the names during…
/*I am unsure if my code for saving the tokens in an array is accurate.
This is so because been whenever I run my program, the code to compare
token[0] with my variable doesn't give an output nor perform assigned function.
Hence I am sure there is…
im have a flex-bison project working on ubuntu linux vmPlayer.
Problem is, I'm trying to use map of string and int in my bison file for int-string casting, and it gives me error in file extra.y:
%{
#include
#include …
template
static T *anydup(const T *src, size_t len) {
T *ptr = malloc(len * sizeof(T));
memcpy(ptr, src, (len * sizeof(T)));
return ptr;
}
Is this proper? Can I expect any errors from this when using an int, long, etc.? I'm…
I have an issue with threads.
I am defining a global variable, a char * that I initialize to NULL, and a mutex.
pthread_mutex_t mutex;
char *minURLTime;
minURLTime = NULL;
Then I initialize my mutex:
pthread_mutex_init(&mutex, NULL);
I then create…
I want to send duplicate string to my bison file.
In my flex file I use it like this
"<" {return strdup(tOPEN);}
">" {return strdup(tCLOSE);}
Is this right things to do?
Or should I use it like below the code.
"<" {…
I have char* flexible array member stored within a stuct. Each of the values within the flexible array member have been strdup'd. I am unsure as how to free each of the strdup'ed values since I do not know exactly how many elements I have stored in…
I've implemented a function that returns a string. It takes an integer as a parameter (age), and returns a formatted string.
All is working well, except from the fact that I have some crazy memory leaks. I know strdup() is the cause of this, but…
I'm trying to create a program with SDL2.
In a certain part of the code, I'm writing functions to grab names of all present files in a given directory path (and keep them in memory) so that, in another function, I can check if a specified file was…
I have a code that has an invalid write in valgrind. What I tried to do was strcat the idx I malloc'd. I would like to know what size to strdup() so I can put spaces in between the number of tokens, which are the in the char *argv[].
Here is a small…