STRDUP(3) BSD Library Functions Manual STRDUP(3)NAME
strdup, strndup -- save a copy of a string
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <string.h>
char *
strdup(const char *str);
char *
strndup(const char *str, size_t len);
DESCRIPTION
The strdup() function allocates sufficient memory for a copy of the string str, does the copy, and returns a pointer to it. The pointer may
subsequently be used as an argument to the function free(3).
If insufficient memory is available, NULL is returned and errno is set to ENOMEM.
The strndup() function copies at most len characters from the string str always NUL terminating the copied string.
SEE ALSO free(3), malloc(3), wcsdup(3)HISTORY
The strdup() function first appeared in 4.4BSD. The strndup() function was added in FreeBSD 7.2.
BSD December 5, 2008 BSD
Check Out this Related Man Page
STRDUP(3) Linux Programmer's Manual STRDUP(3)NAME
strdup, strndup, strdupa, strndupa - duplicate a string
SYNOPSIS
#include <string.h>
char *strdup(const char *s);
#define _GNU_SOURCE
#include <string.h>
char *strndup(const char *s, size_t n);
char *strdupa(const char *s);
char *strndupa(const char *s, size_t n);
DESCRIPTION
The strdup() function returns a pointer to a new string which is a duplicate of the string s. Memory for the new string is obtained with
malloc(3), and can be freed with free(3).
The strndup() function is similar, but only copies at most n characters. If s is longer than n, only n characters are copied, and a termi-
nating NUL is added.
strdupa and strndupa are similar, but use alloca(3) to allocate the buffer. They are only available when using the GNU GCC suite, and suf-
fer from the same limitations described in alloca(3).
RETURN VALUE
The strdup() function returns a pointer to the duplicated string, or NULL if insufficient memory was available.
ERRORS
ENOMEM Insufficient memory available to allocate duplicate string.
CONFORMING TO
SVID 3, BSD 4.3. strndup(), strdupa(), and strndupa() are GNU extensions.
SEE ALSO alloca(3), calloc(3), free(3), malloc(3), realloc(3)GNU 1993-04-12 STRDUP(3)
Hi All,
I have a script (attached) that was working fine on Linux. I compiled it there using g++ CrncyFmt.cpp -o CrncyFmt.o
When I ran it there using eg. CrncyFmt.o 2343.565 2 I get as expected: CharOut = " 2,343.57"
Now we have moved to our test box which is AIX and I... (11 Replies)
Hello everyone,
How to connect hash table with shared memory?.I need to update and retrieve data from the shared memory through hash table.
Thanks in advance (13 Replies)
Hi guys.
I've a question, if we are using a syscall that receives a string allocated dynamicaly to a determined size, or NUL and it will allocate the apropriate size. We should free the memory or the OS will do it for us?
If a function returns a pointer we should free that poiter when we are done... (7 Replies)
Hi All,
I have a simple code which does some computation by matching string patterns.
In brief:
1. The code reads .dat and .txt files.
2. .dat files are huge text files and .txt files contain some important words.
3. I am just doing strstr to find the patterns.
4. The function returns the... (3 Replies)
Hi friends,
I have this problem that I am facing, I want to store an argument which is passed to main, and I want to store it as an array of characters. I can store number arguments with the help of x = atoi(argv). Now suppose I passed the argument Hello to main, how can I store it somewhere in my... (6 Replies)
I am trying to get userinput from stdin and store the lines in an array.
If i do this:
using a char **list to store strings
allocate memory to it
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv)
{
char *prog = argv;
char **linelist;
int... (5 Replies)
Hello,
I am trying to read a text file into linked list, but always got the first and last records wrong.
1) The problem looks related to the initialization of the node temp with malloc(), but could not figure it out. No error/warning at compiling, though.
2) The output file is empty,... (10 Replies)
I am trying to reverse complement DNA sequence (string) with a short c++ code using boost library. Code was compiled without any warning/error, but ran into Segmentation fault.
My guess is the function to return a vector, but not sure.
#include <iostream>
#include <fstream>
#include <string>... (14 Replies)
Hi
We meet errors while running configuration scripts to prepare compiling source code on AIX 7.2. This error does not happen on AIX5.3 and AIX6.1
With the “/usr/bin/sh” from AIX7.2, sometimes , the script runs sucessfully, sometimes not. It’s unstable, and I don’t know why.
When... (10 Replies)
I have an array in an external file, "array.txt", which contains:
char *testarray={"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"};I want to be able to add an element to this array, and have that element display, whenever I call it, without having to recompile... (29 Replies)
Hi, all,
I'm writing a BBS telnet client, and am trying to implement a status bar into it, at the bottom of the screen.
I am using NCurses to accomplish this. So far, it appears to be working, that is, upon connecting to BBS, it
will display the status bar, and then quickly disappear.
... (5 Replies)
Someone, please help on this issue:-
Note : for security reason i didn't mention hostnames and ips.
==============================================================================
# ntpstat
unsynchronised
polling server every 1024 s
Ntpstat showing unsynchronised.
... (29 Replies)
Hi,
I have an array, that works well. But, I want to have it display every other line. Like so, 1, 3, 5, 7, etc, etc.
Here is the relevant code:
I'm sorry for the pastebin link. For some reason, I can't get the code to format properly with the code tags.
code tags work fine... everyone... (4 Replies)