01-27-2009
If he uses something other than NULLs to terminate strings, then he needs his own strlen. If he already has given lengths for data, he doesn't need strlen. But if he thinks writing his own will be faster than the library function that's not too likely. gcc in particular has intrinsics that can reduce it to a vanishingly small number of instructions in some cases and architectures.
He does have a point, though, in that sockets deliver raw data, not strings per-se. They only have nulls on the end if you send nulls, which is not something you want to rely on with data from an uncontrolled outside source. better to deal with data in random lengths than measure it every time.
Last edited by Corona688; 01-27-2009 at 01:13 AM..
10 More Discussions You Might Find Interesting
1. Programming
hello,
i have a problem with strlen. I have written this:
for(y=13,z=0; cInBuf!=' ';y++)
{
cBuf=cInBuf;
z++;
}
len = strlen(cBuf);
out=len/2;
fprintf(outfile,"F%i",out);
If strlen is e.g. 22, it write F22. I want to write F2F2.
How can i do this?... (5 Replies)
Discussion started by: ACeD
5 Replies
2. Shell Programming and Scripting
Hello,
Just a little problem with the ksh function : strlen
I want to use this function in this little ksh program :
while read line ; do
TOTO=$line
TOTONB=strlen($TOTO)
echo $TOTONB (3 Replies)
Discussion started by: steiner
3 Replies
3. Programming
In a declaration, I have:
const char comment_begin = "<!--";
const char comment_end = "-->";
const int comment_begin_len = strlen(comment_begin);
const int comment_end_len = strlen(comment_end);
When I compile, I get the warnings:
emhttpc.c:64: warning: initializer element is not... (10 Replies)
Discussion started by: cleopard
10 Replies
4. Programming
If one wants to get a start address of a array or a string or a block of memory via a function, there are at least two methods to achieve it:
(1) one is to pass a pointer-to-pointer parameter, like:
int my_malloc(int size, char **pmem)
{
*pmem=(char *)malloc(size);
if(*pmem==NULL)... (11 Replies)
Discussion started by: aaronwong
11 Replies
5. Shell Programming and Scripting
Hi, I hope the title does not scare people to look into this thread but it describes roughly what I'm trying to do. I need a solution in PHP.
I'm a programming beginner, so it might be that the approach to solve this, might be easier to solve with an other approach of someone else, so if you... (0 Replies)
Discussion started by: lowmaster
0 Replies
6. Programming
My OS (Debian) and gcc use the UTF-8 locale. This code says that the char size is 1 byte but the size of 'a' is really 4 bytes.
int main(void)
{
setlocale(LC_ALL, "en_US.UTF-8");
printf("Char size: %i\nSize of char 'a': %i\nSize of Euro sign '€': %i\nLength of Euro sign: %i\n",... (8 Replies)
Discussion started by: cyler
8 Replies
7. Programming
I have a fundamental question on C pointer arithmetry..
Suppose i have a c string pointer already pointing to a valid location, Can I just do a
charptr = charptr +1;
to get to the next location, irregardless if my program is 32 or 64 bits?
or should i do it this way:
charptr =... (1 Reply)
Discussion started by: Leion
1 Replies
8. Programming
When i want to use a list of strings
char *list; i never understand it well.
Here is an easy example. It took me long to figure it out, searching the web didn't help much:
#include <stdio.h>
int main(void)
{
char *list = {"foo", "bar", "baz"};
char **pl;
int... (6 Replies)
Discussion started by: tornow
6 Replies
9. Programming
Hello,
This function was copied into my code, which was compiled without error/warning, but when executed there is always Segmentation fault at the end after the output (which seems correct!):
void get_hashes(unsigned int hash, unsigned char *in)
{
unsigned char *str = in;
int pos =... (7 Replies)
Discussion started by: yifangt
7 Replies
10. Shell Programming and Scripting
greetings,
pretty new to php and i think i might be missing some fundamental limitation of isset. i have two php scripts below that are executed by crond, one using --host X and one that does not. and below that are three different attempts at generating a command line that will be executed. the... (8 Replies)
Discussion started by: crimso
8 Replies
LEARN ABOUT XFREE86
strlen
STRLEN(3) Linux Programmer's Manual STRLEN(3)
NAME
strlen - calculate the length of a string
SYNOPSIS
#include <string.h>
size_t strlen(const char *s);
DESCRIPTION
The strlen() function calculates the length of the string pointed to by s, excluding the terminating null byte ('