samedi 18 février 2017

Need to know why this if condition keeps crashing the program

char* strtok(char *a) {
    char delmtrs[2] = { char(32), '.' };
    for (int i = 0; a[i] != NULL; i++) {
        for (int j = 0; j < 2; j++) {
            if (a[i] == delmtrs[j]) {
                a[i] = NULL; 
                return &a[i];
            }
        }
    }
    return 0;
}

I can see that when I set a[i]= NULL the for loop stops, which could be causing the crash, but I tried changing a[i] to any other character. The program still crashes.

Aucun commentaire:

Enregistrer un commentaire