Tuesday, 11 December 2012

Implement strrchr

/*
* This program will search for the occurance of a character
* from the last of the string.
* If found it will return the address of last occurance of that character
* */
char *mystrrchr(const char *s1, int x)
{
const char *p = NULL; /*For copying the address of the string for check*/
while(*s1 != '\0'){
if(*s1 == x)
p = s1;
s1++;
}
return(char *)p;
}

Implement strncmp

/*This program will compare the n-bit of a string s1 with s2. If both string are same up to n-bits it will return Zero else it will returns the difference of the ascii value of 1st unmatched character.*/

int mystrncmp(const char *s1, const char *s2, int n)

{

while(s1 != '\0' && (*s1++ == *s2++) && --n > 1)

;

return (*s1 - *s2);

}

Implement strncat

/*This function will append "n" character of source string "src" into target string "tar" & return Zero. */

char *mystrncat(char *tar, const char *src, int n)

{

char *t;/*retaing the address of target string*/

t = tar ;

while (*tar != '\0')

tar++;

/*Copying from src to tar string*/

while (*src != '\0' && (*tar++ = *src++) && (--n > 1));

*tar = '\0';

return t;

}

Implement strncpy


/*This function will copy "n" character of the source string "src" to the target string "tar" and return Zero.*/

char *mystrncpy(char *tar, const char *src, int n)

{

char *t = tar; /*for Retaing the address tar string*/

/*Copying string*/

while(*src != '\0' && (*tar++ = *src++) && n--);

*tar = '\0';

return t;

}

Saturday, 3 November 2012

Daily quiz no.- 04


Daily quiz no.- 04

Answer it!



Comment your answer without watching others comments first! You may explain your answer
Share it with your friend to see what's there answer!