lzth.net
当前位置:首页 >> 编写strCpy(ChAr*s,ChAr*t)函数,实现把t指向的字符串复制到s中 >>

编写strCpy(ChAr*s,ChAr*t)函数,实现把t指向的字符串复制到s中

代码,mystrcpy#include void mystrcpy(char *a,char *b) { while(*a != '\0' ) *b++=*a++; *b='\0'; } int main() { char *a="test string",b[100]; mystrcpy(a,b); printf("b is %s\n",b); }

char*strcat(char*s,char*t) { char *address=s; while(*s) s++; while(*s++=*t) NULL; return address; }

void strcpy(char *s,char *t){ while ((*t++=*s++)!='\0'); } 修正一下: char * strcpy(char * s, char * t) { char *rt = t; while ((*t++=*s++)!='\0'); return rt; }

char* strcpy(char *s,const char *t) { char* p = s; if (s == 0 || t == 0) return p; while (*s++ = *t++) ; return p; }

第一个格式是对的,它在完成赋值的内容是'\0'时结束;第二个格式是错的,它不会把'\0'复制过去.

#include void strcat(char * t, char * s){ while (*t) t++; while (*s) { if (isalnum(*s)) { *t = *s; t++; } s++; } *t = 0;}void clean(char * s){ char * p = s; while (*s) { if (!isalpha(*s)) { *p = *s; p++; } s++ } *p = 0;}

#include "stdio.h"#include "iostream" unsigned int getlength(char* c) { unsigned int counter = 0; do { ++counter; c++; }while(*c!='\0'); return counter; } void copystring(char* s, char* d) { do { *d=*s; s++; d++; }while(*s!='\0'); *d='\0'; } void main()

int scopy(char *s,char *t){ int i; i=0; while(t[i]){ s[i]=t[i]; i++; } s[i]=0x00; return i; }

char* fncopy(char *s, char *t, int n){ if(s == NULL || t == NULL || n<0) return NULL; if(s == t) return s; char*beg=s; char*end=t+n; while( t!=end)*beg++=*t++; *beg = '\0'; return s;}

C++标准中,wchar_t是宽字符类型,每个wchar_t类型占2个字节,16位宽.汉字的表示就要用到wchar_t .char,我们都知道,占一个字节,8位宽.其实知道了这个以后,要在wchar_t 和 char两种类型之间转换就不难实现了.wchar_t 转换为

相关文档
网站首页 | 网站地图
All rights reserved Powered by www.lzth.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com