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

Strlen() and Non-Latin Characters

I have this code case strlen($search_term) > 15: in my switch statement. I cannot figure out why Greek characters are parsed different. For example a string in Latin with the length of 10 passes the case but if the string is in Greek, it does…
Makis
  • 1,214
  • 3
  • 16
  • 40
2
votes
1 answer

Does strlen() always correctly report the number of char's in a pointer initialized string?

As long as I use the char and not some wchar_t type to declare a string will strlen() correctly report the number of chars in the string or are there some very specific cases I need to be aware of? Here is an example: char *something = "Report all…
lord.garbage
  • 5,884
  • 5
  • 36
  • 55
2
votes
5 answers

My jQuery and PHP give different results on the same thing?

Annoying brain numbing problem. I have two functions to check the length of a string (primarily, the js one truncates as well) heres the one in Javascript: $('textarea#itemdescription').keyup(function() { var charLength = $(this).val().length; …
Stefan P
  • 1,013
  • 2
  • 18
  • 34
2
votes
3 answers

How to find words with length >5 using just 1 array?

I want the user to enter text and that the program finds all words which are bigger than 5 letters and prints them out. scanf("%[^\n]s", ar); l = strlen(ar); for (n = 0; n < l; n++) { while (ar[n] != ' ') { if (ar[n] != ' ') { …
2
votes
5 answers

strlen does not return the right length

I'm currently using strlen method to calculate the lenght of this string : 56 69 56 4F 74 65 63 68 32 00 2C 00 00 27 6F 23 84 0E 32 50 41 59 2E 53 59 53 2E 44 44 46 30 31 A5 11 BF 0C 0E 61 0C 4F 07 A0 00 00 00 04 10 10 87 01 01 the main problem…
Sara Sara
  • 299
  • 1
  • 6
  • 14
2
votes
3 answers

strlen gives larger number than the size of an array

This might be trivial and I hope someone could explain this. Why strlen is giving me larger number than this real size of char array instead of 4: Here is my code: #include #include int main () { char szInput[4]; …
Samer
  • 1,923
  • 3
  • 34
  • 54
2
votes
2 answers

PHP strlen() function abnormal behaviour in enterkey count

I am trying to find the count of following text in php using strlen() function,
Akilan
  • 1,707
  • 1
  • 16
  • 30
2
votes
2 answers

Count consecutive occurence of specific, identical characters in a string - PHP

I am trying to calculate a few 'streaks', specifically the highest number of wins and losses in a row, but also most occurences of games without a win, games without a loss. I have a string that looks like this; 'WWWDDWWWLLWLLLL' For this I need to…
user3061608
  • 21
  • 1
  • 7
2
votes
3 answers

Gnuplot, how I get the length of an value?

I want to know the number of characters of a value. but strlen ( ) is only for strings , not for values. ( strlen(value("zon")) does not work) Example: zon = 12000, len value is 5. Is this possible with gnuplot?
Con
  • 197
  • 2
  • 10
2
votes
1 answer

Uninitialized string offset while calculating string length without using strlen()

"; for ($i = $length - 1; $i >= 0; $i--) { echo $a[$i]; } ?> tried to calculate the string…
2
votes
5 answers

PHP strlen question

Ok I am checking that a string is at least 4 characters long and 25 or less characters short I tried to use strlen like this $userNameSignupLength = strlen($userNameSignup); else if($userNameSignupLength<4 && $userNameSignupLength>25) { …
MrEnder
  • 265
  • 3
  • 7
  • 16
2
votes
3 answers

difference between sizeof and strlen in C linux

The first printf statement is giving output 3 and second giving 20. Can anybody please explain what's the difference between the two here? char frame[20],str[20]; printf("\nstrlen(frame)= %d",strlen(frame)); printf("\nsizeof(frame) =…
user3542109
  • 121
  • 1
  • 3
  • 11
2
votes
1 answer

Writing to a char array after fgets call causes it to be empty according to strlen

as the problem i was having was assignment related and has been solved i've decided it remove the code. Thanks for the help.
choczy
  • 59
  • 5
2
votes
1 answer

C - Reading strings from a text file and arranging them by size

I want to read strings from a text file (one string/word per line) and then arrange them by size. This is my code: void readDic(char* file) { FILE* fr; fr=fopen(file, "rt"); // opening the text file char line[MAX_LINE_SIZE]; char*…
TheStiff
  • 365
  • 2
  • 10
2
votes
2 answers

c fgets retrieves the whole array?

I have a file named phobebook where i retrieve the number of contacts I have(here the int is assigned on variable cc), then saved the names, address etc. problem is when I display the info, the details are there but they are separated with new…
user3266210
  • 299
  • 4
  • 15