You have to end the string with a \0
character. That’s why they are called zero terminated strings.
It is also wise to allocate 1 extra char to hold the \0
.
More Related Contents:
- Why do strings in C need to be null terminated?
- String termination – char c=0 vs char c=’\0′
- What is the output of the following code in C? [closed]
- pointer to string concept in c [closed]
- Can I change the datatype of previously declared variable in C?
- What is the difference between char s[] and char *s?
- Why is this string reversal C code causing a segmentation fault? [duplicate]
- How to use sscanf in loops?
- When should I use ampersand with scanf()
- enum to string in modern C++11 / C++14 / C++17 and future C++20
- How do I create an array of strings in C?
- How does strtok() split the string into tokens in C?
- How to convert enum names to string in c
- Are string literals const?
- Will std::string always be null-terminated in C++11?
- What’s the rationale for null terminated strings?
- How to compare strings in an “if” statement? [duplicate]
- fgets() includes the newline at the end [duplicate]
- What is the proper way of implementing a good “itoa()” function?
- Print all the permutations of a string in C
- Why does char* cause undefined behaviour while char[] doesn’t?
- Concatenating strings in C, which method is more efficient?
- Strange character after an array of characters
- How to remove the character at a given index from a string in C?
- String.indexOf function in C
- Does C support raw string literals?
- Does C have any tools for doing string addition?
- How to concatenate string and int in C?
- Copying non null-terminated unsigned char array to std::string
- Integer to IP Address – C