Coder404
Coder404

Reputation: 742

Can't clear char array

My C application reads a file character by character and stores the char value in a char array. At a certain point, the char array needs to be cleared so another value can be entered. However, when I try to clear it, the chars still remain in the array.

This is how I reset the array:

void resetArray(){
    operand[0] = '\0';
}

What am I doing wrong?

Upvotes: 0

Views: 603

Answers (1)

this
this

Reputation: 5290

Setting the first character as the null terminator will leave the rest of the array in memory intact. Printing the string will not print them, but they are still there.

You have to clear the remaining memory.

memset( array , 0 , sizeof( array ) ) ;

Upvotes: 3

Related Questions