原型:extern char *strncpy(char *dest, char *src, int n); 用法:#include <string.h> 功能:把src所指由NULL結束的字串的前n個位元組複製到dest所指的數組中。 說明: 如果src的前n個位元組不含NULL字元,則結果不會以NULL字元結束。 如果src的長度小於n個位元組,則以NULL填充dest直到複製完n個位元組。 src和dest所指記憶體地區不可以重疊且dest必須有足夠的空間來容納src的字串。 返回指向dest的指標。 舉例: // strncpy.c #include <syslib.h> #include <string.h> main() { char *s="Golden Global View"; char *d="Hello, GGV Programmers"; char *p=strdup(s); clrscr(); textmode(0x00); // enable 6 lines mode strncpy(d,s,strlen(s)); printf("%s\n",d); strncpy(p,s,strlen(d)); printf("%s",p); getchar(); return 0; }
| stpcpy |
| |
原型:extern char *stpcpy(char *dest,char *src); 用法:#include <string.h> 功能:把src所指由NULL結束的字串複製到dest所指的數組中。 說明:src和dest所指記憶體地區不可以重疊且dest必須有足夠的空間來容納src的字串。 返回指向dest結尾處字元(NULL)的指標。 舉例: // stpcpy.c #include <syslib.h> #include <string.h> main() { char *s="Golden Global View"; char d[20]; clrscr(); stpcpy(d,s); printf("%s",d); getchar(); return 0; } |
| memcpy |
| |
原型:extern void *memcpy(void *dest, void *src, unsigned int count); 用法:#include <string.h> 功能:由src所指記憶體地區複製count個位元組到dest所指記憶體地區。 說明:src和dest所指記憶體地區不能重疊,函數返回指向dest的指標。 舉例: // memcpy.c #include <syslib.h> #include <string.h> main() { char *s="Golden Global View"; char d[20]; clrscr(); memcpy(d,s,strlen(s)); d[strlen(s)]=0; printf("%s",d); getchar(); return 0; } |
| strcpy |
| |
原型:extern char *strcpy(char *dest,char *src); 用法:#include <string.h> 功能:把src所指由NULL結束的字串複製到dest所指的數組中。 說明:src和dest所指記憶體地區不可以重疊且dest必須有足夠的空間來容納src的字串。 返回指向dest的指標。 舉例: // strcpy.c #include <syslib.h> #include <string.h> main() { char *s="Golden Global View"; char d[20]; clrscr(); strcpy(d,s); printf("%s",d); getchar(); return 0; } |
| memccpy |
| |
原型:extern void *memccpy(void *dest, void *src, unsigned char ch, unsigned int count); 用法:#include <string.h> 功能:由src所指記憶體地區複製不多於count個位元組到dest所指記憶體地區,如果遇到字元ch則停止複製。 說明:返回指向字元ch後的第一個字元的指標,如果src前n個位元組中不存在ch則返回NULL。ch被複製。 舉例: // memccpy.c #include <syslib.h> #include <string.h> main() { char *s="Golden Global View"; char d[20],*p; clrscr(); p=memccpy(d,s,'x',strlen(s)); if(p) { *p='\0'; // MUST Do This printf("Char found: %s.\n",d); } else printf("Char not found.\n"); getchar(); return 0; } |
|
|
|
|
|