I have a char matrix m[10][10][100] that I use for store user input data. Each iteration I should clear this matrix before store more input. Is there a funtion to help on this?
I have a char matrix m[10][10][100] that I use for store user input data. Each iteration I should clear this matrix before store more input. Is there a funtion to help on this?
Iterate trough it and clear it by yourself, btw, what you mean "clear", delete the current data there is in this array? Also pick up in mind that we're talking about a huge array, doing this operations every input can be very slow.
You could also checkout the "memset()" function.
By "clear" I mean delete the current data there is in this array, tha is, put it in a state like when I declared it. I´m not sure, but I think when a char matrix is declared, each position is initializated with '\0' char. If its true, I should iterate through it and put '\0' in each position.
Am I right?
>>when a char matrix is declared, each position is initializated with '\0' char.<<
That depends on how and where you declared it.
Global variables are initialised to 0.
Static variables are also initialised to 0.
Local variables are not initialised by default.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
>>Global variables are initialised to 0.
>>Static variables are also initialised to 0.
I didnt know that. Its a valuable information. Thanks.
>> Local variables are not initialised by default.
I discovered that by analizing the matrix after it was declared.
In my program, I found out don´t need to clear the matrix after each iteration, because it's a char matrix. Wherever I copy any data to the matrix, through sscanf or strtok, the null char '\0' is always writed at the end of the string. This assures only the new string will be read whenever I parse the matrix.
The program I´m working on is a very simple scratch shell.
Now, I´m working on creating a new process and pass to it the execution of the commands stored on the matrix. I´ve been experimenting some endless looping when I redirect the stdin to a file in the new process. It should be an (missed) pay attention on somewhere on the code, and I´ll still try to find out that before posting a new thread.