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
-5
votes
1 answer

Inconsistency when using strlen

The code below manifests inconsistency if you change SIZE from 7 to 8. If SIZE is 7, the strlen(chars) returns 7; if SIZE is 8, the strlen(chars) returns 9, which is no more equal to SIZE. I am aware of the fact that strlen works for C-string and…
zell
  • 9,830
  • 10
  • 62
  • 115
-5
votes
1 answer

Can't understand strlen expression argument result

#include "stdio.h" #include "string.h" int main(){ char p[]="CALIFORNIA\n"; char *x ="HELLO"; printf("%lu\n",strlen(p+sizeof(p)-sizeof(x)+5) ); } I searched all over but couldn't find what happens when the argument of strlen is an…
momo
  • 1,052
  • 5
  • 16
  • 34
-5
votes
1 answer

length of array with repeated '\0', not strlen

If I need to find out length of a array with repeated '\0' character, what should I do? strlen won't be of use as it will simply stop with '\0'. In that case what is the best solution? For example I have a buf; now I don't know the length. I need to…
ninja.stop
  • 410
  • 1
  • 10
  • 24
-5
votes
1 answer

Need help for strlen

I have a problem, with this and I wanted to know if any of you could fix it will be very appreciated! I am trying to encrypt a message to send to people in my game Problem: When I try to send my message the 1st time gonna works and show the text on…
-5
votes
2 answers

Why do we use 'strlen()' if 'printf()' itself returns the length of the string?

The C function printf() returns the no of characters printed then what makes strlen() different?
-5
votes
1 answer

strlen and free memory

I allocated memory to a pointer to the maximum size of characters it could have. Then I had to write code that will change its values depending on the value that was read from the file and I needed to know what is the length of the value in the…
Dani
  • 79
  • 2
  • 12
-5
votes
2 answers

Whats wrong with this strlen() implementation?

size_t strlen(const char* c) { auto *c1 = c; while(*c1++); return c1 - c; } Mistakes I could find: * missing NULL check for c * c1 should be declared as char pointer (or is it required?) * should typecast to size_t before returning
balajimc55
  • 2,192
  • 2
  • 13
  • 15
-5
votes
2 answers

What is the purpose of strlen($query)-2;

I got this code from google and it fulfills my requirement, but I don't understand the meaning of this line: substr($query,0,strlen($query)-2) Could somebody explain it to me?
Mani Kandan
  • 699
  • 1
  • 10
  • 30
-5
votes
3 answers

How to compare length of 4 strings according to strlen

Write a program that reads 4 Names from the user, and compares the lengths to find the least two in length (strlen). then compares which one of these two alphabetically and prints the first alphabetic ordered one. I have been struggling to compare…
-5
votes
2 answers

strlen doesn't work even with #include in C

Does it not return an int or something? This is a snippet of my code: int wordlength(char *x); int main() { char word; printf("Enter a word: \n"); scanf("%c \n", &word); printf("Word Length: %d", wordlength(word)); return…
Evyione
  • 31
  • 2
  • 10
-5
votes
1 answer

Error in my str class

I'm making my own string class but I got a problem reading the characters of the string while using strlen() to do that. /****str.h****/ class str { private: char *m_ptr; unsigned int m_size; //unsigned int m_capacity; public: …
blackout
  • 84
  • 9
-6
votes
2 answers

Replicating the Strlen function in C

I have been working on my C assignment where I try to replicate strlen() function without actually using it. This is the code I have been trying to get working. However, somehow the main function does not reflect what's happenning in mystrlen()…
-6
votes
2 answers

C : how do I printf "the square root of 1764 is 42 and * in ascii"?

ok so I am learning C and I try to use simple functions to understand basics and here I am stuck whith a segmentation fault I can't manage to make this code working h3lp please thanks you all !!! #include #include int …
CnewB
  • 1
  • 3
-6
votes
1 answer

why strlen () replace a string?

I got a pgm from internet. But I am confused about a code about strlen () function . Is it strlen() replace a string ? I am beginner in this coding .help me . simple code block below : while(NULL != fgets(Buffer, 4095, Input)) { char *Stop =…
-7
votes
1 answer

strcmp always returns 1 even if it ie equal

it always returns 1 even if they aren't same and im wondering that why i have to write down buffer size in scanf_s if i don't the scnaf_s does not work int main(void) { char str1[30] = "push"; char str2[30] = { 0 }; scanf_s("%s",…
1 2 3
46
47