Professional Documents
Culture Documents
Tutorials
Student
Jobs
Courses
Write
Come write articles for us and get featured
Practice
Learn and code with the best industry experts
Premium
Get access to ad-free content, doubt assistance and more!
Jobs
Come and find your dream job with us
o Geeks Digest
o Quizzes
o Geeks Campus
o Gblog Articles
o IDE
o Campus Mantri
My Profile Edit Profile
Logout
Home
Courses
o Practice DS & Algo.
o Algorithms
o Analysis of Algorithms
o Data Structures
o Interview Corner
o Languages
o ISRO CS
o GATE
o CS Subjects
o Web Technologies
o School Learning
o Mathematics
o Maths Notes (Class 8-11)
o NCERT Solutions
o RD Sharma Solutions
o UGC NET CS
o Student
o Jobs
GBlog
Puzzles
What's New ?
Change Language
Related Articles
Related Articles
strdup() and strndup() functions in C/C++
How to pass an array by value in C ?
Reverse words in a given string
Print words of a string in reverse order
Different methods to reverse a string in C/C++
std::reverse() in C++
How to reverse a Vector using STL in C++?
What are the default values of static variables in C?
Understanding “volatile” qualifier in C | Set 2 (Examples)
Const Qualifier in C
Initialization of static variables in C
Understanding “register” keyword in C
Understanding “extern” keyword in C
Storage Classes in C
Static Variables in C
Memory Layout of C Programs
How to deallocate memory without using free() in C?
Difference Between malloc() and calloc() with Examples
Dynamic Memory Allocation in C using malloc(), calloc(), free() and realloc()
How to dynamically allocate a 2D array in C?
How to pass a 2D array as a parameter in C?
Multidimensional Arrays in C / C++
2D Vector In C++ With User Defined Size
Vector of Vectors in C++ STL with Examples
Vector in C++ STL
What is Memory Leak? How can we avoid?
std::sort() in C++ STL
Arrays in C/C++
Bitwise Operators in C/C++
#include<stdio.h>
#include<string.h>
int main()
printf("%s", target);
return 0;
Output:
GeeksForGeeks
strndup() :
syntax: char *strndup(const char *s, size_t n);
This function is similar to strdup(), but copies at most n bytes.
Note: If s is longer than n, then only n bytes are copied, and a NULL (‘\0’) is added at
the end.
Below is the C implementation to show the use of strndup() function in C:
C
#include<stdio.h>
#include<string.h>
int main()
{
printf("%s", target);
return 0;
Output:
Geeks
Reference: Linux man(7)
This article is contributed by MAZHAR IMAM KHAN. If you like GeeksforGeeks
and would like to contribute, you can also write an article
using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org.
See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more
information about the topic discussed above.
Want to learn from the best curated videos and practice problems, check out the C
Foundation Course for Basic to Advanced C.
Like11
Next
How to pass an array by value in C ?
ADVERTISEMENT BY ADRECOVER
RECOMMENDED ARTICLES
Page :
1
2
3
31, May 10
30, Sep 11
31, Mar 16
26, Nov 16
24, Dec 16
23, Apr 17
15, Jul 14
Static functions in C
05, May 10
Pure Functions
10, Dec 11
Article Contributed By :
GeeksforGeeks
Vote for difficulty
Improved By :
MattCT
riusjeff
koushikpmv
Article Tags :
C-Library
CPP-Library
C Language
C++
Practice Tags :
CPP
Improve Article
Report Issue
ADS BY ADRECOVER
WHAT'S NEW
Ad free experience with GeeksforGeeks Premium
View Details
View Details
View Details
ADS BY ADRECOVER
Load Comments
ADVERTISEMENT BY ADRECOVER
Company
About Us
Careers
Privacy Policy
Contact Us
Copyright Policy
Learn
Algorithms
Data Structures
Languages
CS Subjects
Video Tutorials
Practice
Courses
Company-wise
Topic-wise
How to begin?
Contribute
Write an Article
Write Interview Experience
Internships
Videos
@geeksforgeeks , Some rights reserved