Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

mystring-funcs

#include <stdio.h>
void mystrcat(char *s,  char *t)
{

    while(*s)
    s++;
    
    while (*t)
    {
    *s = *t;
    s++;
    t++;
    }
    *s='\0';
    
}

int mystrlen(char *s)
{  
    int len=0;
    
    while(*s)
    {
    len++;
    s++;
    }
    return len;
}

char *mystrcpy(char dest[], const char src[])
{
    int i=0;
    while (src[i]!= '\0') {
        dest[i]=src[i];
        i++;
    }
    dest[i]= '\0';
    return dest;
    
}
int mystrcmp(const char *s1, const char *s2)
{
    while(*s1==*s2){
        if(*s1 == '\0') return 0;
        s1++; s2++;
    }
    return (*s1-*s2);
}
int myatoi(const char *str)
{
    int number =0;
    char *p= str;
    while((*p >= '0') && (*p <='9')){
        number = number*10 + (*p - '0');
        p++;
    }
    return number;
}
int main()
{
    char str1[20] = "Hello-";
    char str2[10] = "World";
    char str3[20];
    char str4[20] = "World";
    char str5[10] = "1998";
    int len=0;
    mystrcat(str1,str2);
    printf("concatinated string is %s \n", str1);
    len = mystrlen(str1);
    printf("length is %d \n", len);
    mystrcpy(str3,str2);
    printf("dest string is %s \n", str3);
    len = mystrcmp(str2,str4);
    if(len == 0)
    printf("strings are equal \n");
    else
    printf("strings are not equal , diff is %d \n",len);
    len = myatoi(str5);
    printf("atoi return value is %d \n", len);
    return 0;
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.