#include
#include
size_t strlen(const char *s){
assert(s != NULL);
unsigned int cnt = 0;
while(*s++){cnt++;}
return cnt;
}
char * strcpy(char *dest,const char *src){
assert(dest != NULL && src != NULL);
char *p = dest;
while(*dest++ = *src++){}
return p;
}
char *strncpy(char *dest,const char *src,size_t n){
assert(dest != NULL && src != NULL);
char *p = dest;
while(n--&& (*dest++ = *src++)){}
return p;
}
char *strcat(char *dest,const char *src){
assert(dest != NULL && src != NULL);
char *p = dest;
while(*dest++){};
--dest;
while((*dest++ = *src++)){};
return p;
}
char *strncat(char *dest,const char * src,size_t n){
assert(dest !=NULL && src != NULL);
char *p = dest;
while(*dest++){};
--dest;
while((*dest++ = *src++) && n--){};
*dest = '\0';
return p;
}
int strcmp(const char *s1,const char *s2){
assert(s1 != NULL && s2 != NULL);
while(*s1 != '\0' && *s2 != '\0' && *s1++==*s2++ );
return *s1 - *s2;
}
int strncmp(const char *s1,const char *s2,size_t n){
assert(s1 != NULL && s2 != NULL);
while(n-->1&&*s1 != '\0' && *s2 != '\0' && *s1++ == *s2++);
return *s1 - *s2;
}
void *memcpy(void *dest,const void *src,size_t n){
assert(dest != NULL && src != NULL);
char *pdest = dest;
const char *psrc = src;
while(n>0){
*pdest++ = *psrc++;
--n;
}
return dest;
}
int main(){
double arr[3] = {1.2,1.3,1.345};
double arr1[3] = {};
int i;
memcpy(arr1,arr,sizeof(arr));
for(i = 0;i<3;i++){
printf("%g\n",arr[i]);
}
}