250 questions
Advice
0
votes
3
replies
89
views
Restrict keyword and pointers to pointers
I'm in C and I have an int ** (2 dimensional array, it's basically a matrix, it's actually set up a little bit complicated but there's no internal aliasing, so it's not relevant).
is this int** ...
3
votes
4
answers
143
views
What's wrong with this code, which gets content (chars) from file and stores it in char**?
I have a small project (ed-like text editor for myself. Just want to edit some config files using it) and I have some problems with it.
workspace_file->flc = malloc(sizeof(char *));
...
0
votes
3
answers
130
views
Accessing information on a 2d array with a double pointer in a struct (C)
In trying to understand pointers, I created a M[x][y] array, a pointer to said array *p_M[x] and a pointer to said pointer **d_p_M. The first pointer points to the first element of a row in the array ...
0
votes
0
answers
65
views
Why do we use a single pointer rather than a double pointer to pass an array to a function? [duplicate]
Why not double pointer to take an array?
I'm having a bit of problem understanding why an array isn't passed as a double pointer (a pointer to a pointer) since the array name itself is a pointer (...
2
votes
2
answers
132
views
why do I need to add an & sign while allocating a memory space inside a functions? [duplicate]
I wanted to try making an allocate function for a cell in a list, but when using it inside another functions, I need to add an "&" sign
I am aware of what "&" means in c (...
1
vote
0
answers
82
views
Marshalling double pointers in C#
I have to interact with a provided C library where one of the functions is declared as follows:
int GetFileList(struct spiflash_file **ptr_spiflash_filelist, int **file_num);
where **...
1
vote
1
answer
256
views
Runtime error: `load of null pointer of type 'char'` when indexing an array
I'm trying to write a trim function, but when I try to use it the compiler is giving me a runtime error or load of null pointer of type 'char' when I try to run this code:
// Trim trailing whitespace
...
-3
votes
2
answers
129
views
Confusion about C pointers
I am sending this message to clear my confusion that I could not manage and handle.
The foo1 function code should work. I am giving the code details for you.
When I run the code, the result is a ...
0
votes
1
answer
587
views
double pointer to the char array
I have been trying to figure out how double pointer works with char * and char [].
What I want to do is to assign a double pointer to the char * or char [] and then change the content.
#include <...
0
votes
2
answers
67
views
What does this double pointer do in c programming?
#include <stdio.h>
#define LENGTH 3
char *words[LENGTH];
int main( int argc, char *argv[] )
{
char *pc; // a pointer to a character
char **ppc; // a pointer to a pointer ...
1
vote
2
answers
82
views
Why regular swap works with a pointer-to-pointer variable?
I know the difference between these two functions: Swap(int *x, int *y) vs Swap(int **x, int **y).
But, I'm not sure how this kind of code works.
How is it possible to swap the address which the ...
1
vote
1
answer
215
views
How to iterate through a dynamic, rectangular matrix in C?
I have to create a matrix with pointers in dynamic memory in C, fill it with random numbers then print it.
This is part of a larger assignment from college (I had to do a whole library of functions ...
1
vote
1
answer
139
views
Is it better to store a 2D image in a flat array or in an array of arrays?
I have two options.
receiving and processing pixel data in a flat array.
If I choose it, I have to use single pointer.
I have to use this code in every repeated pixel data process.
int getIndex(int ...
0
votes
1
answer
91
views
Why does malloc(0) in C not produce an error when working with char pointer pointers
I'm trying to write a simple split function in c, where you supply a string and a char to split on, and it returns a list of split-strings:
#include <stdio.h>
#include <stdlib.h>
#include &...
0
votes
3
answers
136
views
How to understand secondary pointer?
i want to ask a question about pointer:
void fun(const char** a) {...}
1.
const char* b = nullptr;
fun(&b);
2.
const char** b = nullptr;
fun(b);
why use 1 but not 2?
1 is good, 2 donnot work
0
votes
0
answers
28
views
Pointer to Pointer Memory-address [duplicate]
about pointers in C++
why we use ** in pointer to pointer
I just want to know the reason
why we use ** in pointer to pointer
what is the main reason of using double indirections ?what is the logic ...
2
votes
4
answers
934
views
Using double pointers in C
Am doing a task where am supposed to used getline function read input from a user from the terminal. Here is my code:
int main(int ac, char **av)
{
printf("Write something: \n");
...
0
votes
1
answer
142
views
inserting node at the beginning of a circular linked list using void function
I m trying to insert a node at the beginning of a circular linked list using a void function.
When i pass pointer to pointer head in the function because i have to change the head itself, it is ...
0
votes
2
answers
555
views
Incompatible pointer type pointer to array and double pointer to array
So i am new to programming and i have this program that i have to write, it has an array of integers and i have to pass it to a function with a pointer and then with a double pointer.
After i wrote ...
0
votes
0
answers
142
views
Assigning a pointer to "member function pointer" to a pointer to "void"
#include <iostream>
struct Adder {
int a, b;
int operator()() { // member function.
return a+b;
}
};
int main() {
using MemFuncPtr = int(Adder::*)() ;
alignas(64) char buf[64]; ...
0
votes
1
answer
54
views
segfault when setting character of malloced pointer-to-pointer string
In a bigger project i have been working on, i got an Segmentation fault (core dumped), so i managed to reproduce the problem like this:
#include <stdio.h>
#include <string.h>
#include <...
1
vote
0
answers
54
views
How do I create a pointer-to-pointer type in Jython without getting a "pointer only supported for scalar types" error?
I am trying to call external functions inside of a DLL from a Jython script using ctypes.
The prototype is declared as:
extern cl_error_t funcname(const char **varname)
That's why I tried to create ...
1
vote
2
answers
80
views
Struggling to understand how to call a pointer to pointer in scanf
I'm building a program in C to run some simulations for my PhD research. Basically the program uses a function to read an input file with some important values, and then assign these values to ...
0
votes
1
answer
715
views
I am trying to load words from a text file into a binary search tree
I am trying to load words from a text file into a binary search tree.
Each line of the file contains one word.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef ...
0
votes
0
answers
53
views
Why dereferenced pointer to pointer is not the same as pointer? [duplicate]
I recently wrote a MyStack class which would work just like STL stack. Now i decided to write MyStack struct, which I will work with using functions instead of methods
struct Stack
{
int _data;
...