dimanche 28 juin 2015

While loop error while implementing 'strend'

I keep getting errors when I run the program I wrote for 'strlen'. (strlen returns 1 when one string appears at the end of another). I guess it's the first while loop that gives the error, because when I put printf("%c\n", *s); instead of empty ;, it just works fine. Is there something wrong with the syntax???

#include <stdio.h>

int strend(char *s, char *t)
{
    int len;
    int dummy;
    while ( *s++ )
        ; // why error???
    while ( *t++ )
        len++;

    for ( ; len>0 ; len--)
    {
        if ( *(s-len) != *(t-len) )
            return 0;
    }
    return 1;
}

int main() {
    char one[] = "I 0dont like youa";
    char two[] = "ke youa";
    printf("%d\n", strend(one, two));
}

Aucun commentaire:

Enregistrer un commentaire