字符串处理

#include <iostream.h>
#include <assert.h>
char* strcat(char* a, const char* b)
{
 assert(a != NULL &&  b != NULL);
 char * str = a;
 while ( *str++ != '\0' )
    NULL; 
 str--; 
 while ( (*str++ = *b++ ) != '\0')
    NULL;
 return str;
}

int strlen(char *p)
{
    assert(p != NULL);
    if (*p == '\0')
      return 0;
    else
 {
       p = p + 1;
       return strlen(p) + 1;
 }
}

char * strcpy(char * a, const char * b)
{
   assert( (a != NULL) && (b != NULL));
   char * temp = a;
   while ( (*a ++ = *b++) != '\0') 
       NULL;
   return temp;
}

int main(void)
{
 char *a = "world";
 char b[10]= "hello";
    strcat(b, a);
 cout<<"b ="<<b<<endl;
 return 0;
}

 

posted @ 2009-01-22 12:36  谭志宇  阅读(171)  评论(0编辑  收藏  举报