I am very new to C (after many years). I am using lcc64 and have the following statement
char *logMessage = strdup(argv[1]);
I have no idea why I get the error
"operands of = have illegal types 'pointer to char' and 'int"
Any suggestions?
What I'm wondering is why converting a string to a char* seems to make the new char* not equal to the literal string it came from.
If I have:
//raw versions of the string:
string s = "fun";
char* c = "fun";
char* s_convert = strdup(s.c_str());…
I'm trying to run this program where a character array is created and allocated memory dynamically. Later the array elements are populated with the string "hello" for 10 consecutive locations. The values are assigned to the string elements using…
I've never used malloc to store more than values but I have to use strdup to order the lines of an input file and I dont get a way to make it work.
I though using strdup() to get a pointer to each line and later, put each one into a space according…
If I want to return strdup from a function whose return type is char*, then what are the risks or chances of memory leak ?
char* fun () {
return strdup("hello");
}
int main() {
for(;;)
printf("%s\n", fun());
}
I'm trying to use the strdup() function in C but I'm getting an odd error involving malloc. My condensed code is:
void loadEntity(FILE *inFP, entity_t *ent, char *token) {
char buffer[100] = "buffer";
if (strcmp(token, "name") == 0) {
if…
My C program gives segmentation fault when I try to run on Ubuntu.Here is the stack trace.Any help is appreciated
0 0x015383f1 in ?? () from /lib/tls/i686/cmov/libc.so.6
#1 0x01538075 in strdup () from /lib/tls/i686/cmov/libc.so.6
#2 0x00c0a4af…
i have following code which use strdup function
#include
#include
#include
char source[] = "The Source String ";
int main()
{
char *dest;
if ((dest = _strdup(source)) == NULL)
{
fprintf(stderr, " Error…
I am using a std::vector to store some strings, later I try to std::find them but passing through strdup, as shown in the sample code, It does not work, std::find returns last, which means it did not find the string, but I can see that it is there,…
char* XX (char* str)
{
// CONCAT an existing string with str , and return to user
}
And i call this program by:
XX ( strdup("CHCHCH") );
Will this cause a leak while not releasing what strdup() generates ?
It's unlikely that…
I'm currently trying to implement the setenv function in C that sets the value of an environment variable, and I'm concerned about memory leaks in my code flagged by Valgrind due to strdup. I would greatly appreciate your insights in helping me…
I am posting a message here because I am new to assembly programming.
My goal today was to recode a strdup in assembler, so to save my first parameter which is a string (const char*), I have doubts when handling the RSP to reserve space for the…
I am trying to concatenate two string in C
Here is my program, server->vhost.root_dir is char * initialized with strdup.
char *path = strdup(server->vhost.root_dir);
if(path == NULL) …