Could you give me a example code to get first 3 letters of a string by using strlen().Thanks.
Such as like this, no details just a small example.
Code:int strlen ( char * string ) ; printf ( "%d", strlen( "HelloMum" )) ; Output is 13
Could you give me a example code to get first 3 letters of a string by using strlen().Thanks.
Such as like this, no details just a small example.
Code:int strlen ( char * string ) ; printf ( "%d", strlen( "HelloMum" )) ; Output is 13
“Example isn't another way to teach, it is the only way to teach” Albert Einstein
do you know what strlen is for? It's for finding the length of a string. If you only need the first 3 characters, you don't need strlen.
thanks, do you know what could I use to get first 3 characters of a string?
“Example isn't another way to teach, it is the only way to teach” Albert Einstein
thanks dude. This website has a good example who wants to learn about it, should check it: Link
Last edited by BoneXXX; 06-16-2007 at 11:08 PM.
“Example isn't another way to teach, it is the only way to teach” Albert Einstein
This website also has good examples, read the FAQ :\
I looked at the behavior of strncpy() and if the string it's copying is longer than the number of bytes you tell it to copy, it doesn't null-terminate the result. So you need to define a buffer array of 4 chars, and set the last element to '\0' before using strncpy().