strdup Questions
5
Solved
I have some C++0x code. I was able to reproduce it below. The code below works fine without -std=c++0x however i need it for my real code.
How do i include strdup in C++0x? with gcc 4.5.2
note i...
Milagrosmilam asked 6/4, 2011 at 22:34
7
Solved
In C, you can use strdup to succinctly allocate a buffer and copy a string into it. As far as I'm aware, however, there is no similar function for general memory. For example, I can't say
struct m...
Submariner asked 1/12, 2012 at 20:49
8
Solved
I recently became aware that the strdup() function I've enjoyed using so much on OS X is not part of ANSI C, but part of POSIX. I don't want to rewrite all my code, so I think I'm just going to wri...
11
Solved
What is the purpose of the strdup() function in C?
6
Solved
I read that strcpy is for copying a string, and strdup returns a pointer to a new string to duplicate the string.
Could you please explain what cases do you prefer to use strcpy and what cases do ...
3
Solved
Compiling the following code:
#include <string.h>
#define FOO (NULL)
int main(int argc, char *argv[])
{
char *foo;
if (FOO)
foo = strdup(FOO);
return 0;
}
results in the following c...
Erst asked 22/10, 2014 at 12:57
4
Solved
When I compile the short piece of code below (in which we define a string and then use strdup to make a copy), I get 3 warnings: 2 compiler warnings from GCC and 1 run-time warning/error from valgr...
7
Solved
When I use strdup in Microsoft Visual C++, it warns me:
warning C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strdup. See online help fo...
Isolated asked 28/9, 2011 at 11:17
1
Solved
I make programs in C. I read about the strdup() function. From what I could tell, the strdup() function allocates space while the strcpy() does not. But the problem with strdup() is it allocates sp...
1
Solved
I have flex code that copies a string lexeme using strdup().
%{
#include "json.tab.h"
#define YY_DECL extern "C" int yylex()
%}
%option noyywrap
%%
[ \t\n]+ ;
\"[a-zA-Z]+\" {yylval.sval = st...
Vacuity asked 28/6, 2015 at 20:14
3
I'm using Bison & Flex for 1 month more or less, so I'm sorry if I don't see something obvious (but I don't think it is).
I have a problem about freeing memory with Flex Bison. Here is what my...
Convergence asked 20/3, 2014 at 13:48
1
Solved
I want to use POSIX's basename function (as opposed to GNU's).
From the man page:
Both dirname() and basename() may modify the contents of path, so
it may be desirable to pass a copy when call...
3
Solved
Does strdup allocate another memory zone and create another pointer every time?
For example: does the following code result in a memory leak?
void x(char** d, char* s){
*d = strdup(s);
}
int ma...
Ticonderoga asked 20/12, 2013 at 21:7
4
Solved
I am calling strdup and have to allocate space for the variable before calling strdup.
char *variable;
variable = (char*) malloc(sizeof(char*));
variable = strdup(word);
Am I doing this right? O...
4
Solved
In my app, I have am receiving multiple memory leaks. The object is Malloc 48 bytes, and it always originates from the responsible caller strdup. The history of the object only shows it being Mallo...
Dorthadorthea asked 26/3, 2012 at 21:46
5
Solved
While I was working on an assignment, I came to know that we should not use assignments such as :
char *s="HELLO WORLD";
Programs using such syntaxes are prone towards crashing.
I tried and us...
5
Solved
I'm writing a C++ class for a book that contains a name:
class Book {
private:
char* nm;
..........
............
..........
...........
};
I am not allowed to use std::string in this assignment...
Mercado asked 14/3, 2010 at 22:35
10
Solved
I have the following C code fragment and have to identify the error and suggest a way of writing it more safely:
char somestring[] = "Send money!\n";
char *copy;
copy = (char *) malloc(strlen(som...
Haifa asked 26/5, 2009 at 16:49
1
© 2022 - 2025 — McMap. All rights reserved.