250 questions
1
vote
1
answer
545
views
pointer pointer string (char **) from user input in C
I am new to C, I can't seem to find much on pointer pointer char for the purpose that I need it. Here's my code simplified:
int total, tempX = 0;
printf("Input total people:\n");fflush(stdout);
scanf(...
0
votes
6
answers
1k
views
How to evaluate double pointers in c?
I am learning c, and I am quite confused about this double pointer question.
int x = 44;
int *p = &x;
int **t = &p;
bool a = (*t = &x);
I need to tell whether a will be true or false, ...
1
vote
1
answer
97
views
How to obtain data from a memory address pointed by another pointer?
I am working with GenICam library, one of the methods is described as follows:
I am using this method to get camera frames.
We must provide to pBuffer a pointer, the method will return to our pointer, ...
0
votes
0
answers
32
views
Char pointer array and double pointer [duplicate]
How the memory allocation is done for a char pointer array and double pointer.
char *s[]={"knowledge","is","power"};
char **p;
p=s;
cout<<++*p<<*p++<<++*p<<endl;
In the ...
3
votes
1
answer
89
views
How to use pointer-to-pointer's variables?
I am trying this code:
int x[] = {1,5};
int y[] = {3,6};
int *w[] = {x,y};
int **z = w;
printf("%d", **z[1]);
cout<<**z[0];
But it doesn't work. My goal is to access to each element inside the ...
0
votes
1
answer
75
views
C, Dynamic allocation of a matrix: Why is this not allowed?
So I have the following example in some lecture notes
void f(int **p){}
void g(int *p[]){}
void h(int p[2][3]){}
int main(){
int **a;
allocate_mem(a); // allocate memory for a
f(a); // OK!
...
1
vote
1
answer
489
views
Segmentation fault on malloc for double pointer
I'm making a program that reads in text from a file, delimits it into alphanumerical words, and so on. I'm running into an issue where, I've read from the file into a string, and I'm trying to delimit ...
0
votes
2
answers
716
views
How do I convert a char * string into a pointer to pointer array and assign pointer values to each index?
I have a char * that is a long string and I want to create a pointer to a pointer(or pointer array). The char ** is set with the correct memory allocated and I'm trying to parse each word from the ...
3
votes
3
answers
1k
views
How to pass a two-dimensional array to a function in C?
My function prototype is
int** rotate(int **arr, int row, int col, int fl);
where arr is the two dimensional array, row and col is the number of row and columns of the 2D array respectively, fl is a ...
16
votes
2
answers
7k
views
Why the second argument to pthread_join() is a **, a pointer to a pointer?
I am new to using pthread and also not that familiar with pointers to pointers. Could somebody perhaps explain why the second argument of pthread_join() is a void **. Why is it designed like this.
...
-6
votes
2
answers
120
views
What is the meaning of this pointer to pointer statement in C? [closed]
int **arr = (int **)malloc(r * sizeof(int *));
how should i interpret the meaning of the above C code ?
1
vote
2
answers
2k
views
what is the pointer to pointer equivalent in lua
I know that you can use tables in a similar way to pointers in lua. That being said, what would pointers to pointers look like? Would they look something like dp = {p = {}}? if so what would the ...
2
votes
2
answers
71
views
Dynamic memory addressing and deallocation
I'm trying to solve a problem for a web tutorial (non-marked) where I'm implementing a dynamic array. However, it fails in two places:
Where I try to delete a dynamic array in function ...
0
votes
0
answers
122
views
Chain List, story of pointers
I have this following code:
void pushInList(t_chan **chan, char *name, char *nick_user)
{
t_chan *new_channel;
(void)nick_user;
if ((new_channel = malloc(sizeof(t_chan))) == NULL)...
-3
votes
1
answer
55
views
Using an array of pointers-to-pointers to manipulate the pointers it points to (C++)
I've been doing this as an exercise on my own to get better at C++ (messing around with a linked list I wrote). What I want to do is to reverse the list by twisting the pointers around, rather than ...
0
votes
1
answer
199
views
Initialise Pointer to Pointer for struct
i have a console based application in which i am using pointer to a pointer. It is minesweeper game in which i need to create board using pointer to a pointer. I have to pass my this pointer to ...
0
votes
1
answer
6k
views
storing data and printing a double pointer
char** splitInput = malloc(255 * sizeof(char*));
...
while(token != NULL)
{
splitInput[i] = token;
token = strtok(NULL, " ");
i++;
}
I don't know why this code works. In my previous ...
1
vote
5
answers
143
views
Pointer to array type confusion
I thought that if I create a pointer to array type, I will be able to print all of its elements. I wrote a program like this,
#include <stdio.h>
int main()
{
int arr[] = {4,2,3};
//...
1
vote
0
answers
70
views
Setting the values of pointers inside another function
I am having some trouble with pointers in C. Basically, we are tasked with programming an N-ary tree (family tree). Any single node can have any number of children (0, 1, 2, ...). I am stuck at the ...
1
vote
1
answer
103
views
Accessing pointer to pointer of struct using -> operator
I have this code:
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
};
void pointerOfPointer(struct node **reference)
{
struct node *temporary =...
2
votes
3
answers
891
views
Unable to allocate memory inside a function and return it in C [closed]
I want to allocate some memory to a pointer using a function. Following is the code I have written:
#include <stdio.h>
#include <stdlib.h>
int test( unsigned char **q)
{
*q = (...
1
vote
4
answers
2k
views
Assign null to the address of a pointer
How can I deinitialize x inside the free_x function? I have to do it in order to fit to an API method. I can very easily deinitialize x just by assigning null to it but I have to do it inside the ...
0
votes
3
answers
12k
views
Returning a pointer to the beginning of a linked list after adding nodes?
struct node {
struct node *next;
int num;
} Node;
Node *insert(int i) {
Node *head;
for (int c = 0; c < i; c++) {
head = malloc(sizeof(Node));
head.num = i;
...
0
votes
1
answer
41
views
queue structure in C. Accessing pointer in a struct by de-refrencing pointer to that struct
1. struct node {
2. char data;
3. struct node* nxtPtr;
4. }
5.
6. typedef struct node Node;
7.
8. Node* front = NULL;
9. Node* end = NULL;
10.
11. void enqueue(char userData)
12. {
13. ...
0
votes
1
answer
130
views
CUDA: pointer to pointer memory access
I can't figure out what is causing the issue. I get "access violation writing location" error in the last line. Am I not correctly allocating the memory?
typedef struct {
doubleXYZW cen_sum; ...