Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. #include <stddef.h>
  2. #include <stdio.h>
  3.  
  4. unsigned int mystrlen(char *s){
  5.     unsigned int i=0;
  6.     if (s==NULL)
  7.         return NULL;
  8.     do {
  9.         i++;
  10.     } while (s[i]!=NULL);
  11.     return i;
  12. }
  13.  
  14. char *mystrchr(char *s, char c){
  15.     unsigned int i=0;
  16.     if (s==NULL)
  17.         return NULL;
  18.     while ((s[i]!=c) && (i<mystrlen(s)))
  19.         i++;
  20.     if (s[i]!=c)
  21.         return NULL;
  22.     return  s[i];
  23. }
  24.  
  25. char *mystrcpy(char *dest, char *src){
  26.     int i;
  27.     if (dest==NULL || src==NULL)
  28.         return NULL;
  29.     for (i=0;i<=mystrlen(src);i++)
  30.         dest[i]=src[i];
  31.     return dest;
  32. }
  33.  
  34. char *mystrcat(char *dest, char *src){
  35.     unsigned int i,leng;
  36.     leng=mystrlen(dest);
  37.     if (dest==NULL || src==NULL)
  38.         return NULL;
  39.     for (i=0;i<mystrlen(src)+1;i++)
  40.         dest[i+leng]=src[i];
  41.     return dest;
  42. }
  43.  
  44. int mystrcmp(char *s1, char *s2){
  45.     int i=0;
  46.     if (s1==NULL || s2==NULL)
  47.         return NULL;
  48.     do{
  49.         if (s1[i]>s2[i])
  50.             return 1;
  51.         if (s1[i]<s2[i])
  52.             return -1;
  53.         i++;
  54.     } while (mystrlen(s1)==i-1);
  55.     if (i==mystrlen(s2))
  56.         return 0;
  57.     else
  58.         return -1;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement