Thread: array

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    10

    array

    is it possible to nullify a character array which is declared inside a struct........if so show with example.......


    thanks in advance
    pthread

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Do you have a code that nullifies array outside the struct?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    10
    i have a doubt..... that only am asking

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Then answer is yes. Take your code for simple array. Replace it with array-member of the struct and check it. (Even no need to ask). If something will not work - post your code, decribe the problem, and ask the "smart question" ((c) FAQ)
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    If you don't know how to access structure members . . . use the . member access operator, or -> for pointers to structures.
    Code:
    struct s_t {
        int x;
    };
    
    struct s_t thestruct;
    
    thestruct.x = 0;
    For the "arrow" operator: (*thestruct).x is the same as thestruct->x.

    If by "nullify a character array" you mean initialize all of its elements to zero, here is the syntax:
    Code:
    char buffer[BUFSIZ] = {0};
    struct structure_type {
        char buffer[BUFSIZ];
    } bufstruct = { {0} };
    You can also set characters to zero with the memset() function.
    Code:
    char array[BUFSIZ];
    
    memset(array, 0, sizeof(array));
    If you just mean an empty string, then all you have to do is to set the first character to \0 or 0 like a normal string.
    Code:
    char array[BUFSIZ];
    array[0] = 0;
    Are you doing multithreaded programming? Just curious, since your name is pthread.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #6
    Registered User
    Join Date
    Nov 2006
    Posts
    10
    ya dwks very correct iam doing multithreading program

    pthread

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Threaded programming is some deep voodoo for someone who's yet to master even some rather basic C fundamentals.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM