Hello, ive recently been making a program, and am trying to do some file i/o so that it can log information. Ive been trying to do it via a class. Well, i ran into a problem just clearing the char arrays (for my purposes they need to be cleared to 0 before i can use them). So far i havent found a simple way to do it, char myArray[100] = 0 didnt work. I've been trying to do it via a member function. Heres the class:
class FILEIO
{
public:
string fileName;
char harvest[1000];
char sendToFile[1000];
// Clears a char array
void clearCharArray( char arrayToClear[] )
{
int arrayLength = 0;
// Get the length of the array passed
arrayLength = sizeof( arrayToClear );
for( int i = 0; i < arrayLength; i++ )
{
if( arrayToClear[i] != 0 )
{
arrayToClear[i] = 0;
}
}
}
};
Im sure im probably missing something simple, but i cant seem to find it. Here is how im implimenting it in my program:
FILEIO testVar;
testVar.harvest[1000];
for( int i = 0; i <= 1000; i++)
{
cout << "Test var pos " << i << " is: " << testVar.harvest[i] << endl;
}
testVar.clearCharArray( testVar.harvest );
system("PAUSE");
for( int i = 0; i <= 1000; i++)
{
cout << "Test var pos " << i << " is: " << testVar.harvest[i] << endl;
}
Im still new to using classes, incase you havnt noticed