Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pointers Ques #2

Status
Not open for further replies.
May 3, 2002
633
US
Regarding pointers, what does the representation mean with two asterisks, such as:

char **s



 
A pointer to pointer of type char.
Overpractical coders: Pointer to string array.

Fun example:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define arbitrary 17

char **stringArrCreate(int);

int main(void) {
int i = 0;
char *stringpt[] =  {&quot;one&quot;,&quot;two&quot;,&quot;three&quot;};
char **pointstring = stringpt;
time_t mytime;
   
   time(&mytime);
   srand(mytime);
   while (i < 3) {
         printf(&quot;Original: %s\n&quot;, pointstring[i]);
         printf(&quot;Random array...\n&quot;);
         pointstring = stringArrCreate(3);
         printf(&quot;Random: %s\n&quot;, pointstring[i]);
         pointstring = stringpt;
         i++; 
   }
return 0;
}



char **stringArrCreate(int num) {
int i, p;
char **retArr = malloc(num * sizeof(char *));

        for (i=0 ; i < num ; i++) {
             retArr[i] = malloc(arbitrary * sizeof(char));
                       p=0;
                       while (p < (arbitrary - 1)) {retArr[i][p] = (char)(1 + rand() % 255); p++;};
                       retArr[i][p+1] = '\0';
        }   
return retArr;
}

OUTPUT:
Original: one
Random array...
Random: <(°~ãØvéÒC¥ìx
Original: two
Random array...
Random: ëìç<&quot;J׺ÉQÐeA·á
Original: three
Random array...
Random: (ñ&#9618;&#9618;ÆéCäûw+&
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top