double-pointer

How to work with pointer to pointer to structure in C?

Hi, I want to change member of structure under double pointer. Do you know how? Example code typedef struct { int member; } Ttype; void changeMember(Ttype **foo) { //I don`t know how to do it //maybe *foo->member = 1; } Thanks for any help. ...

Converting from a jagged array to double pointer in C#

Simple question here: is there any way to convert from a jagged array to a double pointer? e.g. Convert a double[][] to double** This can't be done just by casting unfortunately (as it can in plain old C), unfortunately. Using a fixed statement doesn't seem to resolve the problem either. Is there any (preferably as efficient as possib...

Assigning memory to double pointer?

I am having trouble understanding how to assign memory to a double pointer. I want to read an array of strings and store it. char **ptr; fp=fopen("file.txt","r"); ptr=(char**)malloc(sizeof(char*)*50); for(int i=0;i<20;i++) { ptr[i]=(char*)malloc(sizeof(char)*50); fgets(ptr[i],50,fp); } instead of thi...

How do I properly turn a const char* returned from a function into a const char** in C?

In short, I would like to do this: const char **stringPtr = &getString(); However, I understand that you can't & on rvalues. So I'm stuck with this: const char *string = getString(); const char **stringPtr = &string; I can live with two lines. Am I introducing problems with this hack? I should have no fear of passing stringPtr out ...

Linked list head double pointer passing

Hi, I have seen this in some book/ tutorial. When you pass in the head pointer (of linked list) into a function, you need to pass it as a double pointer. For eg: // This is to reverse a linked list where head points to first node. void nReverse(digit **head) { digit *prev=NULL; digit *curr=*head; digit *next; while(cu...

How to qsort an array of pointers to char in C?

Suppose I have an array of pointers to char in C: char *data[5] = { "boda", "cydo", "washington", "dc", "obama" }; And I wish to sort this array using qsort: qsort(data, 5, sizeof(char *), compare_function); I am unable to come up with the compare function. For some reason this doesn't work: int compare_function(const void *name1,...