Array pointer as function argument?

This is a discussion on Array pointer as function argument? within the C Programming forums, part of the General Programming Boards category; Hello, I have been asked to implement a method Code: void word_not(lc3_word_t *R, lc3_word_t *A) which, as you can see, ...

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    1

    Array pointer as function argument?

    Hello,

    I have been asked to implement a method

    Code:
    void word_not(lc3_word_t *R, lc3_word_t *A)
    which, as you can see, takes 2 pointers to a array of BITS, defined as follows:
    Code:
    typedef enum {
        ZERO = (uint8_t) 0, ONE = (uint8_t) 1
    } BIT;
    
    typedef BIT lc3_word_t[16];
    The main method invokes the function:

    Code:
    word_not(&result, &a_value)
    which passes the address of two lc_word_t types to word_not. The function is supposed to negate each bit in a_value (NOT function) and write it into the corresponding bit in result.

    What should I put in the body of word_not to accomplish this? I begin by looping from 0 to 15 (a total of 16 times, the length of the word type), but I am not sure how to check & store elements in arrays when I am given only pointers (addresses?) to the arrays. I am very confused what the data fields for the pointer arugments look like when addresses are passed into them.

    I have tried different things like making BIT pointers (BIT *) but when I print the contents of result it always appears to have addresses instead of BITs. What should I do?

  2. #2
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Quote Originally Posted by mtn_student View Post
    ... What should I do?
    I would suggest you learn about pointers. Specifically, pointers to pointers. Take a look at Prelude's Pointer Tutorial.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing address or pointer as argument to function
    By Edelweiss in forum C Programming
    Replies: 7
    Last Post: 08-17-2011, 01:38 AM
  2. Replies: 12
    Last Post: 05-24-2011, 06:57 AM
  3. pointer as function argument
    By bertazoid in forum C Programming
    Replies: 1
    Last Post: 09-23-2010, 11:27 AM
  4. pointer and function argument question.
    By stevfletchcom in forum C Programming
    Replies: 5
    Last Post: 06-15-2010, 12:07 AM
  5. Pointer to List Iterator As Function Argument
    By bengreenwood in forum C++ Programming
    Replies: 8
    Last Post: 06-17-2009, 06:30 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21