strstr 函数
来源:互联网 发布:网络拓扑分析 编辑:程序博客网 时间:2024/05/25 19:56
/* strstr example */#include <stdio.h>#include <string.h>int main (){ char str[] ="This is a simple string"; char * pch; pch = strstr (str,"simple"); strncpy (pch,"sample",6); puts (str); return 0;}
/* 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): */ 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;}