Questions tagged [string.h]

A header file from the C standard library that defines various functions for interacting with C strings.

In C a string is a null-terminated set of contiguous char values, often referred to via a pointer. The string.h header defines many common methods for interacting with such strings. These methods are guaranteed to be portable as a part of the standard library, but may have other limitations or security concerns.

169 questions
21
votes
6 answers

or ?

Which is the best way to include the standard header string.h in a C++ project? Using the [dot]h at the end, like this: #include or just writing #include Or, maybe, using another way that I don't know? Thanks!
Overflowh
  • 1,103
  • 6
  • 18
  • 40
13
votes
3 answers

What is the difference between memcpy() and strncpy() given the latter can easily be a substitute for the former?

What is the significant difference between memcpy() and strncpy()? I ask this because we can easily alter strncpy() to copy any type of data we want, not just characters, simply by casting the first two non-char* arguments to char* and altering the…
Thokchom
  • 1,602
  • 3
  • 17
  • 32
11
votes
2 answers

strcmp() return different values for same string comparisons

char s1[] = "0"; char s2[] = "9"; printf("%d\n", strcmp(s1, s2)); // Prints -9 printf("%d\n", strcmp("0", "9")); // Prints -1 Why do strcmp returns different values when it receives the same parameters ? Those values are still legal since…
Bilow
  • 2,194
  • 1
  • 19
  • 34
7
votes
3 answers

Are strupr() and strlwr() in string.h part of the ANSI standard?

I was looking for this on internet and in every place with the functions of string.h these two are not mentioned. Is because what? They aren't in every compiler?
exsnake
  • 1,767
  • 2
  • 23
  • 44
7
votes
6 answers

Why copy function arguments into local variables?

What is the reason for strlcpy.c to copy the arguments into local variables: size_t strlcpy(char *dst, const char *src, size_t siz) { char *d = dst; const char *s = src; size_t n = siz; /* Copy as many bytes as will fit */ if (n…
Micha Wiedenmann
  • 19,979
  • 21
  • 92
  • 137
6
votes
6 answers

strcat in c program is not working

#include #include void main() { char *str1="hello"; char *str2="world"; strcat(str2,str1); printf("%s",str2); } If I run this program, I'm getting run time program termination. Please help me. If I use this: char…
user3815049
5
votes
1 answer

how to use strxfrm in C language?

I ask a question to know the usage of "strxfrm" in C. I know the function is to transform a string according to current locale configuration. but I don't know what "transform" is, and how this function transforms. For example, I tried a code like…
Luciano Jeong
  • 325
  • 1
  • 10
5
votes
1 answer

What do each of the str-function abbreviations/acronyms mean?

The C standard library string.h contains several functions to manipulate strings, all of which start with str and end with an abbreviation. Some of these abbreviations are obvious: strlen string length strcpy string copy strcmp string compare Some…
MD XF
  • 7,860
  • 7
  • 40
  • 71
5
votes
0 answers

definition for __ THROW __nonnull

I see the definition of memmove() and memcpy() which both contain the line __THROW __nonnull ((1, 2)); where can I find this defined ?
vaibhav.pnd
  • 175
  • 2
  • 8
4
votes
2 answers

including C/C++ headers in Xcode 4

I've been using a C++ library without problems on projects built with Xcode 3, but I'm now getting build problems on projects built with Xcode 4. Drop the library into the Xcode 4 project and it builds fine, but as soon as I #include it, I get a…
Eric
  • 16,003
  • 15
  • 87
  • 139
4
votes
7 answers

Why strlen function works without #include?

Quick question: strlen[char*] works perfectly regardless whether I #include or not All I get from compiler is a warning about implicit declaration, but functionally it works as intended. Why is that?
James Raitsev
  • 92,517
  • 154
  • 335
  • 470
4
votes
1 answer

How to inline string.h function on linux?

I want to optimize some code such that all the functions in string.h will be inlined. I'm on x86_64. I've tried -O3, -minline-all-stringops and when I do "nm a.out" it shows it is calling the glibc version. Checking with gcc -S, I see the…
tz1
  • 41
  • 3
4
votes
2 answers

Where to find my system's implementation of standard C library functions?

for example, the strrev() function. i know that it's declared in string.h, and i wanna to figure out how it is implemented. so where could i the source code? OS: Windows XP SP3 IDE: Pelles C 6.50 RC3
Lion
  • 965
  • 10
  • 21
4
votes
4 answers

Find the length of string array with strlen()

I have been trying to find the length of string which has an array of chars with strlen() function but it is not working. The code I am using is something like this: string s[]={"a","b","c"}; int len = strlen(s.c_str()); It produces the following…
DeadCoder
  • 87
  • 1
  • 2
  • 9
3
votes
1 answer

undefined reference to `strnstr' how to fix it and run strnstr

I need to reproduce behavior of strnstr function. I want to test strnstr but can't compile program, its written "implicit declaration of function strnstr [-Wimplicit-function-declaration]" and "undefined reference to strnstr". I included header…
ivoriik
  • 155
  • 1
  • 11
1
2 3
11 12