4
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by template<>
1

Outside of changing array[index] to *(array + index) everywhere I'm not sure I understand what you need to do...

0

I think he needs to know how to dynamically allocate the array...

char *buffer = NULL;//<-- good style dictates initializing to nullptr.
buffer = new char[1024];//<-- array of 1024 characters.
//use array with familiar notation
delete [] buffer;//<-- delete the allocated memory so you don't "leak" it.
buffer = nullptr;//<-- good style.  delete doesn't do this for you.

Nevermind.

Edited by pseudorandom21: Woops, didn't notice he had done so.

0

You are on the right track, below is sample of array using index and pointer.

#include <iostream>

int main( int argc, char *argv[])
{
    const size_t LIMIT = 8;
    int buffer[LIMIT] ={0};

    // array access using index notationn
    for(size_t i=0; i < LIMIT; i++)
    {
        buffer[i] = i;
    }
    
    // array access using pointer notation
    for(size_t j=0; j < LIMIT; j++)
    {
        std::cout << *(buffer+j) << std::endl;
    }

    return 0;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.