View Single Post
  #1 (permalink)  
Old May 3rd, 2006, 10:06 AM
perstam perstam is offline
Authorized User
 
Join Date: Apr 2006
Posts: 17
Thanks: 2
Thanked 0 Times in 0 Posts
Default How to convert subscripts to pointers

Hello,

How do I convert the following to use pointers instead of subscripts?

short i;
char words [2000];
for (r=0; r < NumRows; r++)
      cout << words[r];

In the assignment we were given we were told to dynamically allocate an array, read an input file of strings, and store each string in the array preceeded by a one-byte field containing the length of that string. Further the assignment says to not leave unused elements after each string.

The only way I can figure out how to do this is to create another temporary array and do a memcpy after properly positioning the pointer and then do the cout from the temporary array.

Sam Stamport
__________________
Sam Stamport
Reply With Quote