[ create a new paste ] login | about

Link: http://codepad.org/oZzuKv6v    [ raw code | output | fork ]

C, pasted on Mar 18:
void str_cat(char*p1,char*p2)
{
    while (*p1 != '\0') p1++;
    int i = 0;
    while (p2[i++] != '\0')
    {
        *p1 = p2[i - 1];p1++;
    }
    *p1 = '\0';
}
int str_cmp(char*p1,char*p2)
{
    while (*p1 != '\0' && *p2 != '\0')
    {
        if (*p1 != * p2) return *p1 - *p2;
        p1++;p2++;
    }
    return *p1 - *p2;
}
int str_len(char*p1,char*p2)
{
    int n = 0;
    while (*p1 != '\0') { p1++; n++; }
    while (*p2 != '\0') { p2++; n++; }
    return n;
}
int main()
{
char s1[100]="hello ";
char s2[]="world!";
str_cat(s1, s2);
printf("%s\n", s1);
int n = str_cmp("aaa", "ab");
printf("%d\n", n);
n = str_len("aaa", "ab");
printf("%d\n", n);
}


Output:
1
2
3
4
5
hello world!
-1
5

Exited: ExitFailure 2


Create a new paste based on this one


Comments: