Skip to main content
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

15 30 50 per page
1
2 3 4 5
47