Skip to main content
Filter by
Sorted by
Tagged with
0 votes
2 answers
67 views

C strlen() returns the wrong String length (character count) when using umlauts [duplicate]

I'm working on a C program, which takes an input in form of a parameter and then needs the length of the string to continue its work. Unfortunately I'm facing a massive issue in form of a wrong ...
GoldNova's user avatar
  • 353
1 vote
2 answers
69 views

Unable to get length of arg - C [closed]

basically I'm trying to get the length (using strlen) of an argument, but i keep getting this error. From what I've understood it means that I'm giving an array of pointers to char arrays instead of a ...
Jack's user avatar
  • 23
2 votes
3 answers
160 views

Why is the strlen here equal to 25?

Just so I can confirm if what I think is going on is really going on. The following code prints out 25 when i give it the (26 letter) alphabet as an input, is it 'cause fgets always automatically sets ...
Guilherme Cintra's user avatar
2 votes
1 answer
127 views

Why doesn't the compiler optimize strlen() calls in a loop, despite it being a pure function? And how would [[reproducible]] affect this?

I have two functions that convert a string to lowercase. The first one calls strlen() in every iteration, while the second one only calls it after modifying the string. I expected the compiler to ...
Andy Lee's user avatar
2 votes
3 answers
121 views

C strlen on char array

I'm new to programming, so I was practicing with C. Then I ran to a problem with my code: #include <stdio.h> #include <string.h> int main() { char a[] = "Hello"; printf(&...
hasaanE's user avatar
  • 23
0 votes
1 answer
73 views

User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script

I am trying to write a little program, which is resistant against buffer overflow and similar vulnerabilities. Since we cannot trust the user input, I thought it would be a good idea to concatenate ...
Sir Muffington's user avatar
4 votes
0 answers
95 views

Is there a better way to search any byte from a long value?

In OPENJDK's StringSupport class, there are following codes checking if there could be a '\0' byte in a long value: private static final long HIMAGIC_FOR_BYTES = 0x8080_8080_8080_8080L; private static ...
benrush's user avatar
  • 307
3 votes
1 answer
159 views

Strlen function giving wrong length when there are non-english characters in string

I have a program that accepts non-english characters also as an input field. Because we use strlen, it has failed to give expected length while calculating the length of the string when there is a non-...
Bover's user avatar
  • 39
0 votes
0 answers
99 views

add_action hook is not working on user_register in wordpress

I have a wordpress site, and my registration url is Registration URL. I have registered a hook to modify user_login after registration if username is more than 10 digits. if user given mobile number ...
PRATAP KUMAR KOTTI's user avatar
1 vote
1 answer
100 views

c++, How to display an error if user inputs more than one char

I have been trying to find a solution for my school project. The program should display an invalid error if the user enters "Y Y". Currently the program still accepts it and moves on to the ...
notblinkz's user avatar
0 votes
1 answer
138 views

Why +1 in realloc for string in C? If it's for null terminator, then how does strlen() measures len of the str if there's no null byte at the end? [duplicate]

This code is from a problem in HackerRank (Q: Printing Tokens in C). #include <stdio.h> #include <string.h> #include <stdlib.h> int main() { char *s = malloc(1024 * sizeof(char))...
Prabash's user avatar
  • 15
0 votes
1 answer
71 views

Casting from int array to char pointer in C

int v_1[10] = { -1,1000,2 }; int a; a = strlen(((char*)v_1 + 1)); I'm having trouble understanding why the 'a' variable is equal to 5 in this particular case. I'm also struggling to grasp the ...
Sako's user avatar
  • 13
-1 votes
2 answers
166 views

Why is "-1 < strlen(s)" equal to 0?

char* s =(char*) "sss"; int j = -1; printf("%d", j < strlen(s)); It's mainly about the difference between j < 3 and j < strlen(s). In the above code, the printf() ...
Houxiong Yao's user avatar
0 votes
0 answers
54 views

Why is the string length of buf1[12] = "hello world?" 13? [duplicate]

I have the code and output below, why are the string length of buf1 and buf2/buf3 different? #include <stdio.h> #include <string.h> int main() { char buf1[12] = "hello world?&...
Mary's user avatar
  • 11
0 votes
2 answers
48 views

String concatenation not working properly in C using sizeof() but it works for strlen() [duplicate]

#include <stdio.h> int main(void) { char strp[] = "hello"; char strq[] = " world"; strcat(strp,strq); puts(strp); //hello world printf("%d",...
Priyanka Govindarajan's user avatar
0 votes
2 answers
140 views

Unsigned char* instead of char*

Why most c functions with string in param usually has definition char* and not unsigned char*? According to my understanding unsigned char* is more generic. And how to deal in situations when I have ...
vico's user avatar
  • 18.1k
0 votes
1 answer
157 views

When the parameter of strlen is a non zero terminated string, its return value is unsafe in IF statesments?

I have been troubled by a problem of strlen for a long time, here is the code: char stack_protect[1000] = {0}; char temp[100] = { 0 }; memset(&temp, 1, 110); int len = strlen(temp); ...
shunji XIE's user avatar
1 vote
0 answers
157 views

Is strlen() not actually located in the DLL/Static library?

I was trying to assess effectiveness of my custom strlen() implementation versus the default C function. inline ui64 Sl(const char *cs) { const char *sbeg = cs--; while(*(++cs) != 0) { ...
ScienceDiscoverer's user avatar
1 vote
1 answer
356 views

Speed up strlen using SWAR in x86-64 assembly

The asm function strlen receives the link to a string as a char - Array. To to so, the function may use SWAR on general purpose register, but without using xmm register or SSE instructions. The ...
HeapUnderStop's user avatar
0 votes
0 answers
47 views

page fault error with SIMD strlen (using SWAR in integer registers, not SSE) [duplicate]

The asm function strlen receives the link to an string as a char - Array. To to so, the functions may use SIMD on general purpose register, but without using xmm register or SSE instructions. The ...
HeapUnderStop's user avatar
-1 votes
3 answers
123 views

Why strlen() is giving wrong value for a char array with undefined array size?

#include<stdio.h> #include<string.h> int main(){ int a[]={1,2,3,4}; int size= sizeof(a)/sizeof(int); printf("\nSize/capacity of integer type array(with no limit) %d\n",size)...
cookie's user avatar
  • 11
-7 votes
1 answer
103 views

strcmp always returns 1 even if it ie equal [closed]

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&...
amj0215's user avatar
1 vote
1 answer
39 views

Extra characters appearing when pthread_create is called with a struct as an argument to the thread

I observed that when I pass a struct as an argument to the thread, the string member of the struct is few characters longer inside the thread. So basically, in main, s-dev is 12 characters long. And ...
RaviPathak's user avatar
-1 votes
2 answers
120 views

in dev c++ my library is missing how to install it [closed]

//my code is #include <stdio.h> int main() { char txt[] = "xyz"; printf("%d", strlen(txt)); return 0; } //error is strlen is not declared in this scope //it should work my ...
Abhijit Kumar Mehta's user avatar
0 votes
3 answers
155 views

Understand Strlen applied to int array with char * cast

I'm currently stuck on this problem. I have thefollowing code: int v[10] = {-1, 1000, 2}; int a; a = strlen((char *)v+1); printf("strlen result for (char *) v+1: %d\...
Santo's user avatar
  • 81
-1 votes
3 answers
799 views

Understanding parameters of strlen in C

I am a bit confused on why my code is not iterating a string in C programming. Essentially. I have this function here int atoi(const char *s[]){ printf(" The length is %d",strlen(s)); ...
Khandkar Islam's user avatar
0 votes
2 answers
60 views

Wrong strlen returning char Matrix

char t[2][5] = {" * "," * "}; printf("%d\n",strlen(t[0])); Output: 11 Why is this happening and how can I print just the length of the first string? Each string ...
tt0686's user avatar
  • 1,849
3 votes
1 answer
15k views

Depreciated strlen(): Passing null to parameter #1 ($string) of type string is depreciated

your text The above warning is displayed in PHP 8.1 after upgrading from PHP 7.4 Any ideas on how this code can be changed for PHP 8.1 compatibility? private function cleanInput2($strRawText, $...
Andy's user avatar
  • 53
0 votes
0 answers
37 views

How to prevent my code to count `\0` as one character? [duplicate]

I'm attempting to make strlen in C standard library on my own. Following is my code and the strlen func I made is given the name mystrlen in the script below. #include <stdio.h> //int ...
XYJ's user avatar
  • 11
-1 votes
2 answers
131 views

Segmentation fault 11 when making strlen in my own

I am trying to create strlen in C's standard library by myself like following, named it mystrlen. I added other parts to make it run. I used vim editor to write the code and gcc to run the code. The ...
XYJ's user avatar
  • 11
0 votes
1 answer
87 views

"while ( strlen($tmppwd) < 20 )..." returns strings shorter than 20 characters

I am trying to generate a random string in the exact length of 20 characters and getting unexpected behavior from my program, so curious about what I am missing. Here is the code: <?php $tmppwd ...
anrui71's user avatar
-2 votes
4 answers
713 views

Modify itoa to process a floating point string with decimal point operator into ASCII char 23(123.456) in the output

Having trouble C language debug step into process decimal point operator in a floating point sting of numbers. Example: 1234.5678, itoa() output stops at 4 and terminates out array string with '\0' ...
user20874661's user avatar
-2 votes
1 answer
192 views

How to run php strlen function on entire array? [duplicate]

I have an array of strings, and I want to find the sum of the lengths of all the strings in the array. Eg: $array = ['One', 'Two', 'Three']; strlen result is 3 3 5 and the sum is 11. How can this be ...
Adi's user avatar
  • 27
0 votes
2 answers
199 views

Understanding code of function strlen in C Programming

I was given a solution to the problem of recreating the function strlen in C Programming and it was the following, I need help understanding what the code is actually doing. void *ft_memset(void *b,...
TenTwentyFour's user avatar
1 vote
2 answers
132 views

Count consonants in a word randomly found in an array

I want to take a random string of the array and should count the consonants of the random string. Problem is it did not count the letters from array_rand(). Here is what I get at this point: $woerter =...
blacks07's user avatar
0 votes
2 answers
336 views

Strlen() Vs Strcmp for checking empty char array variable

#include <iostream> #include <cstring> int main() { char c1[5]; char c2[5]; if ( strlen(c1) == 0) { std::cout<<" c1 empty"; } if (strcmp(...
Build Succeeded's user avatar
1 vote
1 answer
154 views

Why are the standard library functions so fast?

I wrote a simple code to test mystrlen by comparing it to the standard library strlen on a 2089360 byte string. I used two versions of mystrlen and both are very far from the standard strlen runtime, ...
username's user avatar
-4 votes
1 answer
347 views

.length(), strlen(n), and sizeof(n) does not work with string and cstring [closed]

I'm trying to write code that outputs the length of a string. int main(){ string s1, s2; scanf("%s %s", &s1, &s2); //Doesn't work. cin >> s1, s2; //Works, I inputed ...
Naufal Zafran Fadil's user avatar
1 vote
1 answer
77 views

"strlen" does not give the exact number of characters

I have a WordPress Template with a loop of articles where I want to show the characters that every articles have. I do it this way: <?php $length = strlen( utf8_decode( get_the_content() ) ); echo $...
herrfischer's user avatar
  • 1,828
0 votes
3 answers
165 views

Trying to output the length of a string using strlen() through a pointer

I am trying to output the length of a string using strlen(). But I want to do it through a pointer. Here's what I tried: ` #include <stdio.h> #include <string.h> int main() { char a[]=...
Pankit Shah's user avatar
0 votes
0 answers
361 views

I have a problem with finding end of string in assembly

the code: .text _start: .global _start mov r2, #0 adr r1, msg ldrb r5, =newline getlen: ldrb r3, [r1,r2] add r2, r2, #1 cmp r3, r5 bne getlen p: ...
hilaw00's user avatar
  • 35
0 votes
1 answer
79 views

Why is strlen conting the null character here? [duplicate]

Normaly strlen does not count the null terminator at the end of the string. But the below code prints the string count with the null terminator. Can anyone explain me why? int main(){ char name[...
Ayush Kumar's user avatar
0 votes
2 answers
124 views

How to get array length for array of strings

I want to find the number of elements in that array, but as far as I know I'm not allowed to use strlen or sizeof. strlen(array[0]) gives out 5 cause apple consists of 5 characters, but I need length ...
Valen7ino's user avatar
0 votes
1 answer
534 views

Data Matrix Barcode split to different data

I have a data matrix barcode that have the input Data Matrix Barcode = 0109556135082301172207211060221967 21Sk4YGvF811210721 I wish to have output as below:- Items Output Gtin 09556135082301 Expire ...
devilgg86's user avatar
0 votes
1 answer
238 views

How to get string length in function

How can I get the length of the buffer in the function using pointers? #include <stdio.h> #include <stdlib.h> void fun(char *(buffer)) { printf(strlen(buffer)); } int main() { ...
user avatar
0 votes
0 answers
65 views

what is the NOT instruction doing to eax in assembly [duplicate]

repnz scas al,BYTE PTR es:[edi MOV eax,ecx NOT eax value of eax changed from 0xfffffffc to 0x3 after these lines.
Thrain's user avatar
  • 1
1 vote
5 answers
725 views

Is it faster to use strlen() than just check for null character in a for loop?

I've only been able to find two posts related to this topic. In one post, the code in question was written such that strlen() was called in every iteration of the loop, which many users pointed out ...
anonymousBeaver's user avatar
0 votes
2 answers
289 views

Inaccurate length of string when using 'strlen'

I am getting inaccurate string length when printing the length of a string using the strlen function. I am getting the output for string a as 5 (which is correct), but when I am printing the length of ...
Manas Saha's user avatar
-1 votes
1 answer
48 views

comparing string repetitively returns wrong value

In the below program I am trying to copy string data "eth0" into the array of structure containing string data and a count defined as below. strcmp returns true for the first index but for ...
user avatar
1 vote
2 answers
1k views

Recursion to find length of a string in C

I am trying to find the length of a string by recursion using the following code: #include <stdio.h> int string_length(char *s, int x); int main(void) { int length = 0, x; char string[] ...
Leuel Asfaw's user avatar

1
2 3 4 5
15