功能:複製字串
/* strncpy example */
#include <stdio .h="">
#include <string .h="">
int main ()
{
char str1[]= "To be or not to be";
char str2[40];
char str3[40];
/* copy to sized buffer (overflow safe): */
/* sizeof 取得陣列長度 */
strncpy ( str2, str1, sizeof(str2) );
/* partial copy (only 5 chars): */
strncpy ( str3, str2, 5 );
str3[5] = '\0'; /* null character manually added */
puts (str1);
puts (str2);
puts (str3);
return 0;
}
參考出處:
http://www.cplusplus.com/reference/cstring/strlen/?kw=strlen</string></stdio>
沒有留言:
張貼留言