Tagged Questions
0
votes
1answer
29 views
How do 2-D arrays and dynamic allocation work?
So my idea:
A 2-D array is an array of arrays. If an array is X by Y, then each X points to an array with length Y. Is that part correct? Is that why also when you want to dynamically allocate an ...
0
votes
1answer
42 views
using malloc() with 2d array, not getting expected results
Program takes a malloc'd char * from another function into a malloc'd heigth x width grid. I can't help but think it's the way I'm filling the grid that's faulty. For debugging I've added the print of ...
-2
votes
2answers
64 views
2-D Array with malloc playing tricks
After reading tutorials, I adopted a way to create 2-D array with malloc. But to my surprise, changing allocation code with many variants, gives me the same output.
Consider:
...
0
votes
2answers
80 views
how to allocate arrays and 2D arrays with max length by malloc in c while accessing to them?
I am coding a program which takes a text file as an input, makes the index of the words of it and prints the output(the index) in a file and in the screen.
the input file may be huge. but we KNOW ...
1
vote
3answers
95 views
how I can allocate an array of pointers and a 2D array by malloc in C?
I am coding a program which takes a text file as an input, makes the index of the words of it and prints the output(the index) in a file and in the screen.
the input file may be huge. but we KNOW ...
2
votes
1answer
157 views
Realloc double 2D array in C
I wrote an function which should realloc the array for each input. I think that function works well, but when I'm trying to work with the array I got segmentation fault.
Input:
[1,2] [6,3] [2.5,3.5]
...
0
votes
3answers
407 views
Using malloc for 2D array pointer causes segmentation fault
I am getting a segmentation fault in the initializeStruct function.
I want a 2D Array pointer. Each 2D array index holds a struct of three types.
Here is the struct:
struct cacheLine {
int ...
0
votes
0answers
95 views
2d array can not convert from int* to int
I am trying to assign values to a 2d int array in C.
int **worldMap;
I want to assign each row to the array, so I do this in a loop:
worldMap[0][sprCount] = split(tmp.c_str(), delim);
sprCount++;
...
3
votes
2answers
155 views
Segmentation fault on initializing a 2D array
I've checked that my code is properly carving out memory space, but as soon as I try to initialize my 2D array to some values and then sum up the values, I receive a segmentation fault on just a 2x2 ...
1
vote
1answer
267 views
difference b/w allocating memory to 2D array in 1 go or row by row
what would be the impact in accessing of array or in memory allocation for these two cases:
1.
int **arr;
arr = malloc( sizeof(int) * row * column );
2.
int **arr;
arr = malloc( ...
0
votes
2answers
433 views
Assigning values to 2D array created using malloc
I created a 2D character array using malloc and have been trying to assign its values to '\0'.
char **predicate_array = malloc(no_of_lines_in_data_map);
for(int i = 0; i < ...
0
votes
3answers
100 views
Initialising a 2d-array with zeros; printing its values reveals that not every element contains a 0
I already searched for an answer here, but I couldn't find something that suits my case.
I have a function make_array(), which generates a 2-dimensional array, and has to fill it with zeros.
When ...
0
votes
3answers
131 views
Char ** usage and printing
In C, I am using a char ** to hold a series of strings.
Here is my code:
char ** c;
//now to fill c with data ????
//cannot change:
printf ("%*s%s", 0, "", *c);
while (*++w)
printf (" %s", *c);
...
1
vote
1answer
573 views
Using a pointer to a dynamic 2D Array within a struct
I have been writing a piece of code for my coursework in electromagnetic simulation and I have run into a problem. I decided to do a bit extra by expanding the original calculations to really large ...
3
votes
3answers
405 views
How to malloc a 2d jagged array using a pointer passed by reference to a function in C
I have a 2D jagged array declared in my main() block. This is to be passed to a function to have memory allocated to it. The following is the most reduced case which compiles but crashes when it runs. ...
1
vote
1answer
697 views
Save 2D Dynamic Array (Matrix) for Global Access c
I am trying to save a 2D Array that is populated using a function to global memory. Many matrices are processed and upon success, the correct Matrix needs to be saved for access to numerous functions.
...
2
votes
3answers
384 views
Getting a very annoying segmentation fault… mallocing 2d array in C
I'm having a little trouble with this. First of all, this is for a simple graphics library that I was writing.
What I'm doing is making it possible to declare multiple "virtual screens", with ...
4
votes
4answers
8k views
C Programming: malloc() for a 2D array (using pointer-to-pointer)
yesterday I had posted a question: How should I pass a pointer to a function and allocate memory for the passed pointer from inside the called function?
From the answers I got, I was able to ...