Home > front end >  How do I solve this pointer-for loop in C?
How do I solve this pointer-for loop in C?

Time:11-08

regexp and src are both strings, and count is a pointer to a counter used to scroll the string. It should get out as soon as ']' is found in regexp, but it doesn't seem to be working.

int inParent(char *src, char *regexp, int *count) {
    int check = 0;

    printf("%d", *count);
    for (*count = 0; *(regexp   *count) != ']'; *count   1) {
        if (*(regexp   *count) == *src)
            check = 1;
    }

    if (check == 1)
        return 1;
    return 0;
}

CodePudding user response:

Your count is not incrementing.

int inParent(char *src, char *regexp, int *count) {
    int check = 0;
    printf("%d", *count);
    for (*count = 0; *(regexp   (*count)) != '\0'; *count  = 1) {
        if (*(regexp   (*count)) == *src)
            check = 1;
    }

    if (check == 1)
        return 1;
    return 0;
}
  • Related