Reputation: 227
So, I have this code:
void stringCounter( char cp[], int counter[] ) {
char c;
for ( int i = 0; strlen(cp); i++ ) {
c = cp[i];
// Checking to see if the variable c is alphanumeric...
if ( isalnum(c) ) {
if ( c >= 'A' && c <= 'Z' ) {
counter[c - 'A']++;
} else {
counter[26]++;
}
}
}
return;
}
And I have a bad access error on line 5 (of my listed code). I really don't know how to fix this error! I have tried making things pointers, tried not making things pointers, but really can't get it. Usually, I can debug my programs fairly well, but I am really having trouble with this one.
Any help is appreciated.
Upvotes: 0
Views: 49
Reputation: 47824
You are simply incrementing i
without any boundary checking
for ( int i = 0; i< strlen(cp); i++ ) {
^^ fix this
Upvotes: 1