#include <string.h>
...
char otherString[6]; // note 6, not 5, there's one there for the null terminator
...
strncpy(otherString, someString, 5);
otherString[5] = '\0'; // place the null terminator
More Related Contents:
- optimized sum of an array of doubles in C [duplicate]
- How to get all possible combination of 2xn matrix [closed]
- How to resolve a variable for char length? [closed]
- MIPS program that implements the same algorithm in C
- How to achieve function overloading in C?
- How to correctly use the extern keyword in C
- ‘float’ vs. ‘double’ precision
- Are parallel calls to send/recv on the same socket valid?
- Post-increment on a dereferenced pointer?
- Returning a pointer to an automatic variable
- Why is strtok() Considered Unsafe?
- In C, does a pointer to a structure always point to its first member?
- How to find the element of an array that is repeated at least N/2 times?
- Efficient integer compare function
- What does __init mean in the Linux kernel code?
- How to use the addr2line command in Linux?
- Getting absolute path of a file
- How to use “zd” specifier with `printf()`?
- Why can’t I create an array with size determined by a global variable?
- In C, given a variable list of arguments, how to build a function call using them?
- How do C compilers implement functions that return large structures?
- Why can’t the size of a static array be made variable?
- Difference between “pointer to int” and “pointer to array of ints”
- x86_64 : is stack frame pointer almost useless?
- Why is strtok causing a segmentation fault?
- How do I make an infinite empty loop that won’t be optimized away?
- Function declaration inside of function — why?
- how to detect a file is opened or not in c
- How can I malloc a struct array inside a function? Code works otherwise
- How to write/read to FLASH on STM32F4, Cortex M4