Thread: Clearing char matrix

  1. #1
    gangemi
    Guest

    Clearing char matrix

    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?

  2. #2
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    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.

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    7
    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?

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>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]

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    7
    >>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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 06-16-2006, 09:23 PM
  2. code condensing
    By bcianfrocca in forum C++ Programming
    Replies: 4
    Last Post: 09-07-2005, 09:22 AM
  3. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  4. comparing fields in a text file
    By darfader in forum C Programming
    Replies: 9
    Last Post: 08-22-2003, 08:21 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM