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)
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)
Hi all,
I have a perl script which declares two variables and calls another perl script which accesses those variables. But I am unable to access the variables in the called script. My script is as follows:
my $ENV{a}="20";
system("perl called.pl");
and my called.pl contains:
print... (3 Replies)
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)
I have been getting some flack recently for my use of strlen() and strnlen(). Honestly I have always just taken their functionality for granted as being the easiest way of getting the length of a string. Is it really so much better to do pointer arithmetic? What am I gaining besides more... (3 Replies)
Hi!
Some minutes ago I've posted a question related with sed regexps because I need to catch information sended with forms with GET action. This is the post: https://www.unix.com/shell-programming-scripting/127800-regular-expression-sed.html
But now I have a new question. Does cgi scripts have... (0 Replies)
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)
Hello All,
I am getting this error while compiling my application on IBM AIX 5.3.
As I tried to define _XOPEN_SOURCE=500 in makefile, that didn't work.
Please help us to resolve the error. (0 Replies)
Hi! I've a C program as shown below..
The line numbers and the statements of the program are separated by a space..
1 #include<stdio.h>
2 char a,b,c;
3 float x,y,z;
4 int main()
5 {
6 int d,e,f;
7 // further declarations
8 // further declarations
9 /* body*/
10 }
11 void fun1()
12... (1 Reply)
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
LEARN ABOUT PHP
strtok
STRTOK(3) 1 STRTOK(3)strtok - Tokenize stringSYNOPSIS
string strtok (string $str, string $token)
DESCRIPTION
string strtok (string $token)
strtok(3) splits a string ($str) into smaller strings (tokens), with each token being delimited by any character from $token. That is, if
you have a string like "This is an example string" you could tokenize this string into its individual words by using the space character as
the token.
Note that only the first call to strtok uses the string argument. Every subsequent call to strtok only needs the token to use, as it keeps
track of where it is in the current string. To start over, or to tokenize a new string you simply call strtok with the string argument
again to initialize it. Note that you may put multiple tokens in the token parameter. The string will be tokenized when any one of the
characters in the argument are found.
PARAMETERS
o $str
- The string being split up into smaller strings (tokens).
o $token
- The delimiter used when splitting up $str.
RETURN VALUES
A string token.
EXAMPLES
Example #1
strtok(3) example
<?php
$string = "This is an example
string";
/* Use tab and newline as tokenizing characters as well */
$tok = strtok($string, "
");
while ($tok !== false) {
echo "Word=$tok<br />";
$tok = strtok("
");
}
?>
The behavior when an empty part was found changed with PHP 4.1.0. The old behavior returned an empty string, while the new, correct,
behavior simply skips the part of the string:
Example #2
Old strtok(3) behavior
<?php
$first_token = strtok('/something', '/');
$second_token = strtok('/');
var_dump($first_token, $second_token);
?>
The above example will output:
string(0) ""
string(9) "something"
Example #3
New strtok(3) behavior
<?php
$first_token = strtok('/something', '/');
$second_token = strtok('/');
var_dump($first_token, $second_token);
?>
The above example will output:
string(9) "something"
bool(false)
NOTES
Warning
This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. Please read the section on
Booleans for more information. Use the === operator for testing the return value of this function.
SEE ALSO split(3), explode(3).
PHP Documentation Group STRTOK(3)