Tagged Questions
1
vote
1answer
37 views
segmentation fault : Dynamic memory allocation for Multidimenional array in c
I tried to create Multidimensional array dynamically in c; but i am getting segmentation fault!
int **arr=malloc(sizeof(int*) *row);
printf("&ar:r%d arr:%d %d\n\n",*arr,arr,arr[0]);
...
3
votes
1answer
81 views
2D array passing to a function
I've reading this question but I'm not able to get the resulting code to solve the problem.
How should I change this in order to make it work?
void print2(int ** array,int n, int m);
main()
{
...
2
votes
2answers
51 views
How to copy part of an array from a 2d array into another array in C
So I have the following:
int from[2][3] = { {1,2,3}, {2,3,4} };
int into[3];
into = memcpy(into, from[0], 3 * sizeof(*into));
I want to copy 'from' in to the array 'into' so that 'into' = { 1, 2, ...
0
votes
3answers
46 views
2D pointer to act like 2D array
In C, I am trying to declare a 2D array outside of any function so that it can be shared by the functions. I know in the single dimensional case you can do the following(and make it behave LIKE an ...
1
vote
2answers
56 views
2D arrays passed through functions in c
I'm having a problem with my program. I need my program to read from a text file, the first consists of the dimensions of the 2d array the rest is the contents of the array. I have coded the readWord ...
2
votes
2answers
60 views
Pointer to contiguous 2D array
I'm using gcc version 4.8.0 with flags -Wall -std=gnu99.
I need to dynamically allocate the memory for a contiguous 2D array using malloc in C; this fact is nonnegotiable. However, for ease of use I ...
1
vote
1answer
69 views
Pointer to multidimensional array
I'm trying to address matrix of struct, but some goes wrong.
This the code:
typedef struct {
bool state;
float val;
char ch[11];
} st_t;
st_t matrix[3][5];
int main(int argc, char ...
0
votes
3answers
66 views
For “char list[3][10];” why does all of these work as scanf() %s arguments---&list[i],list[i],&list[i][0]?
Isn't char* the only valid argument type for the %s format specifier used in the format specifier string of scanf()?If so,in my program why each one of these work exactly the same for both scanf()'s ...
2
votes
1answer
33 views
For an X dimensional array where X is greater than 1,is only the first dimension optional,rest are mandatory?
I am trying to get my head around this but since I am new to C I just can't imagine how it will be at or beyond 3D arrays.I know we have to mention the size of static 1D arrays,but in 2D arrays,the ...
1
vote
3answers
62 views
Assigning multi-dimensional arrays and incompatible types
I've been trying to write a function that will put out values between 0 and 1 which will, in turn, be used to generate a Perlin Noise. Whenever I try to compile the code I get this: error: ...
-1
votes
2answers
76 views
How to access elements in double pointer style matrix
double **matrix = NULL;
matrix = (double **)malloc(sizeof(double *) * N); // N is the size of the square matrix
for(int i=0; i<N; i++)
{
matrix[i] = (double *)malloc(sizeof(double)*N);
}
// ...
2
votes
5answers
70 views
Iterating through many arrays in C
I have a header file that has many arrays. Each array pair (i.e. x0, y0) are the same length, but different pairs have different lengths.
numPaths[] = 4;
pathLengths[] = {12, 11, 13, 10};
int x0[] ...
2
votes
2answers
66 views
reading from file and pass to a two dimensional array in C
I want to read a text file and put it's data into a 2 dimensional array. This code works for a small text file like 0 1 1 1 0 1 1 0 1 1 1 1 but gives segmentation fault for a big text file and 648x512 ...
-1
votes
2answers
73 views
Multidimensional array of char pointer
Good day to everyone,
there's some kind of big deal that I cannot figure out.
I create a multidimensional array of pointers:
char *listA[5000][2];
In particular condition, I want that specific ...
0
votes
3answers
117 views
c style string and dynamic allocation in c++
I must implement a bunch of methods that allocates, modify and free a 2D array of c-style string. I cannot use string nor vectors nor any stl container.
getNewMat :
char*** getNewMat(int w, int h){
...