Questions tagged [strlen]

A standard C function that returns the length of a string.

This function calculates the length of the string, excluding the terminating null byte \0. It is defined in the <string.h> standard header.

Documentation for C strlen.

692 questions
3
votes
4 answers

how to find length of an unsigned char pointer in C?

I want to find size or length of an unsigned char pointer in a function where that pointer is an argument to that function.Near the pointers declaration size is coming correctly. But when i am trying to find size in function it is giving 4. How can…
QtUser
  • 185
  • 2
  • 2
  • 12
3
votes
4 answers

snprintf + Pebble

I'm developing for Pebble and I'm off to a rough start. I'm trying to populate a text_layer with 2 strings and 2 values, something like this: WAIT AVG: 3 MAX: 5 Since malloc is not supported in Pebble SDK, I can't use sprintf, hence I'm stuck with…
gh0st
  • 214
  • 3
  • 15
3
votes
3 answers

PHP strlen() nor mb_strlen() returning unexpected results

With PHP, I'm Trying to determine the length (number of characters) in strings such as these: 1 1.1 1.1.1 1.1.2 1.1.3 1.1.3.1 1.1.3.2 1.1.4 1.1.5 1.1.6 1.1.7 etc. When the length of these strings are measured with mb_strlen() or strlen(), the…
Edward
  • 159
  • 1
  • 1
  • 12
3
votes
3 answers

strlen on array returns 5 in php

From the docs - int strlen ( string $string ) it takes string as a parameter, now when I am doing this- $a = array('tex','ben'); echo strlen($a); Output - 5 However I was expecting, two type of output- If it is an array, php might convert it into…
Trialcoder
  • 5,816
  • 9
  • 44
  • 66
3
votes
1 answer

sizeof character and strlen string mismatch

As per my code, I assume each greek character is stored in 2bytes. sizeof returns the size of each character as 4 (i.e the sizeof int) How does strlen return 16 ? [Making me think each character occupies 2 bytes] (Shouldn't it be 4*8 = 32 ? Since…
Suvarna Pattayil
  • 5,136
  • 5
  • 32
  • 59
3
votes
5 answers

Cannot convert string to const char

I have this function and the compiler yells at me saying "Cannot convert string to const char". void DramaticLetters(string s, short TimeLength) { for(int i = 0, sLen = strlen(s); i < sLen; i++){ cout << s[i]; …
skittles sour
  • 479
  • 1
  • 4
  • 7
3
votes
4 answers

Does the '\0' at the end of the string also get included here?

If I declare a string with 10 elements like this: char s[10]; then does the '\0'at the end occupy the 10th place or the 11th? Basically my question is that do we get 1 element less in the string? And if I use the strlen() function to find this…
Nirvan
  • 147
  • 1
  • 1
  • 6
3
votes
1 answer

Handling char* in C# (strlen function?)

I'm dealing with a char* in C# code (in an unsafe section). Is there any way to call the strlen function from C#. It goes against all common sense to have to write a custom strlen function to search for the null terminator. Isn't there a way to call…
Ian
  • 4,169
  • 3
  • 37
  • 62
2
votes
4 answers

Why is variable length array forbidden: "C90 forbids variable length array"?

I know that I'm not supposed to do this in C90, and it's a rather basic stuff. char name[strlen(s)]; ArrayLength.c:11: warning: ISO C90 forbids variable length array ‘name’ Did they want me to specifically use malloc? I'm just curios here about…
oz123
  • 27,559
  • 27
  • 125
  • 187
2
votes
1 answer

What is the difference between mblen and strlen?

What is the difference between mblen and strlen? Is today multi-byte character encoding used in Windows, Linux or Mac OS? Is multi-byte character encoding same as fixed-width character encoding in Windows?
Amir Saniyan
  • 13,014
  • 20
  • 92
  • 137
2
votes
2 answers

loop to count length of string Assembly ARM

I have a string, and I want to loop it to count the length of the string. main: MOV R1, #0 loop: CMP R1, #10 BGT loop ADD R1, #1 B loop_end loop_end: string: .asciz "Hello World\n"
David
  • 23
  • 3
2
votes
1 answer

Fast generic strlen() implementation that can accept arbitrary terminator character

template size_t strlen(const char *str) { const char *char_ptr; const unsigned long int *longword_ptr; unsigned long int longword, magic_bits, himagic, lomagic; for (char_ptr = str; ((unsigned long int)…
Huy Le
  • 1,439
  • 4
  • 19
2
votes
2 answers

Why does this C program to calculate string's length give a wrong output?

I have written this program which accepts a string as an input and return the length of it. #include #include #define MAX 100 int main() { char a[MAX]; int len; printf("Enter a string: "); fgets(a, MAX, stdin); …
Aryan Soni
  • 76
  • 10
2
votes
1 answer

Find Length of string without counting spaces

I'm making program that finds length of string entered by user. Everything is working but program also counts spaces. So, how to find length of string without counting spaces?
sefisko
  • 35
  • 4
2
votes
3 answers

Problem with string - lenght is not correct - some chars included not displayed

I wanted to upgrade the Magento Ogone module to match the new SHASign calculation. It's working fine now but there is a problem ... I have an issue with some strings returned by a Magento method : Mage::getUrl('ogone/api/accept'); It returns me a…
antoineg
  • 98
  • 6