About 246,000 results
Open links in new tab
  1. How to calculate the length of a string in C efficiently?

    /** * @desc calculate the length of str. * @param1 *str pointer to base address of char array. * @param2 size = capacity of str to hold characters. * @return int -1 in case of NULL, else …

  2. Find length of string in C (without using strlen)

    Jan 12, 2012 · In the above program, gets() returns the entered string. We print the length using the first printf. The second printf() calls gets() and prints the entered string using returned …

  3. c - Find the size of a string pointed by a pointer - Stack Overflow

    Nov 25, 2012 · if ptr length is an argument of a function it's reasonable to use pointers as a strings. we can get string length by following code: char *ptr = "stackoverflow"; …

  4. Calculating length of a string in C - Stack Overflow

    Jan 26, 2013 · int strlength(const char *myStr){ //variable used for str length counter int strlength = 0; //loop through string until end is reached.

  5. c - Calculate length of string without using strlen() function - Stack ...

    I wrote a code to calculate the length of a string without using the strlen function. The code below works correctly if i enter a string with no spaces in between. But if i enter a string like "My …

  6. Counting the Whole String Including The Spaces in C

    Jan 11, 2019 · strlen already includes spaces, since it counts the length of the string up to the terminating NUL character (zero, '\0'). Your problem is that that the %s conversion of scanf …

  7. How to get length of a string using strlen function

    Feb 26, 2017 · strlen(str.c_str()); // It may return wrong length. In C++, a string can contain \0 within the characters but C-style-zero-terminated strings can not but at the end. If the …

  8. c - Different ways to calculate string length - Stack Overflow

    Apr 11, 2011 · Actually, on rereading this question and the comment on your previous answer, I don't see what the point is in using sprintf() just to calculate the concatenated string length. If …

  9. c - Determining the Length of a String Literal - Stack Overflow

    Sep 22, 2012 · If the strings would've been pointers, you would get the size of a pointer instead the length of the string. This is not guaranteed to work . If the fields are aligned, this may yield …

  10. Finding the length of an integer in C - Stack Overflow

    Jun 18, 2010 · the right question is not the length of the integer, but which is the minimal number of decimal digits needed to represent that number (held into a C int). log10 is your friend: …