Tagged Questions
0
votes
1answer
28 views
SDL_BlitSurface argument pointer of an 2D array of structure containing a SDL_Rect
I am in the beginning of a game and I'm stuck in the Blit_Surface step. My CodeBlocks compiler says invalid type argument of -> (have BrickStruct)" at compiling. It seems like it wants a pointer to ...
0
votes
3answers
26 views
(*twod)[3] vs *(twod)[3] C Pointers
I'm learning C and have a question of: Explain the difference between int (*twod)[3] as a parameter as compared to int *(twod[3]). I don't really know what the difference is completely. If someone ...
1
vote
2answers
59 views
Is the statement *a[i]++ /= K valid?
Array initialization Code:
int m = 100;
int n = 50;
int i = 0, j = 0;
float **a = (float**)malloc(m*sizeof(float*));
for (i = 0; i < m; i++)
{
a[i] = (float*)malloc(n*sizeof(float));
for ...
2
votes
2answers
53 views
Reallocating a 2d array if initialized like so: char (*A)[size] = malloc(sizeof(char[size][size]))
char (*A)[size] = malloc(sizeof(char[size][size]));
If I initialize size as 10, but eventually I need more memory, how can I reallocate memory for A without losing its contents?
I tried something ...
1
vote
4answers
110 views
C++ How to declare pointer to 2D array [duplicate]
I have a portion of code that goes like this (assume all types are int):
for(int i = 0; i < h; ++i)
{
for(int i = 0; i < h; ++i)
{
if(...)
{
a = B[i][j]
...
0
votes
1answer
48 views
What is the way to store a 2-D array pointer? [duplicate]
Suppose I have a 2-D array of floats:
float a[1024][1024];
I want to store the pointer to array
I did:
float** temp = a;
but doesn't seem to work. It gives the error:
main.cpp: In function ...
1
vote
2answers
43 views
Edit a 2D array through a function in C
I have this function :
void foo( char tab[8][8] )
I want this function to edit the values of the tab array, so i tried theses syntax :
void foo( char *(*tab)[8][8] )
void foo( char *(tab)[8][8] ...
1
vote
4answers
73 views
How can I point to a 2D array?
I have a 2D array.
int MARIO[4][4];
I want to show the values of this array on the screen. The problem is that I don't know how to declare a pointer to a 2D array. Can anyone help?
1
vote
3answers
49 views
Non access violation for 2D array using pointers
I am trying to create a 2D dynamic array using pointers:
int** Grid;
Grid = new int*[5];
for (int i=0;i<5;i++) { Grid[i] = new int[5]; }
std::cout << Grid[4][300] << std::endl; // ...
3
votes
3answers
59 views
Why does 2 dimension array passing to function requires its size?
Inspired this quiestion .
Why does -
void display(int p[][SIZE]) // allowed
and
void display(int p[][]) // not allowed
?
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 ...
0
votes
1answer
54 views
Dynamically Creating an Array of Char Pointers in C
I am trying to make a function that dynamically adds the pointers of selected words from an input array (allTerms) to an array that it will eventually return (myTerms). The pointers point to various ...
2
votes
3answers
89 views
Passing a 2D Array into Function in C
Here is my code:-
void display(int *p)
{
printf ("%u\n", p);
printf ("%u\n", p+1);
}
int main()
{
int a[3][4] = {
1,2,3,4,
5,6,7,8,
9,0,1,2
...
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
4answers
107 views
Pointer to 2D array changes address when I print it
I can't seem to understand why is my pointer changing address in this situation :
int *load(FILE *fp, int * vector, int w, int h){
//other coding
int array[w][h];
int *ptr = &array;
...
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++;
...
1
vote
2answers
77 views
Game of Life Segmentation Fault in C
Im new to C, linux etc my code compiles and runs but as soon as I enter my first user inputs I get a segmentation fault. If someone could point out what is wrong with my code that would be very help ...
2
votes
1answer
114 views
Game of Life Problems in C [closed]
Im creating the Game of Life Program which I created a working copy of but im having issues making it so that the user can enter the grid's x and y(rows and columns) when I try alter my code to do it ...
-2
votes
3answers
93 views
About 2D-array pointer in C [closed]
Here defined an array:
int a[2][5]={{1,2,3,4,5},{6,7,8,9,10}};
and what does the statement mean?:
int *p = (int*)(&a+1);
Why the output of *p is 6 ?
printf("%d",*p);//6
...
1
vote
2answers
147 views
The K&R method of reducing arrays to pointers
The K&R method of reducing arrays to pointers:(An excerpt from arrays and pointers in C)
K&R tried to create a unified treatment of arrays and pointers, one that
would expose rather than ...
1
vote
3answers
92 views
2D Array and pointer to a pointer
Question from a past exam paper:
"Which of the following:
int a[4][4], (*b)[4], *c[4], **d;
Could you pass into a function expecting a pointer to a pointer to an int
ie
int funct(int **);
...
0
votes
1answer
1k views
C Access 2D char array via Pointer
I am trying to access a 2D array of chars. I have a pointer on right address but somehow dreferencing is not working.
char ary[5][8];
char temp[8];
int i;
char **a_ptr = &ary;
for(i=0; ...
1
vote
1answer
97 views
Pointer to statically defined two-dimensional array [on hold]
Code (compiled using gcc -std=c99) ...
#include <stdio.h>
#include <stdlib.h>
typedef int mytype[8][8];
int main(void)
{
mytype CB;
for (int r=0; r<8; r++) {
for (int ...
1
vote
1answer
217 views
How to assign a pointer a 2D square array of unknown size?Whats wrong in the following function?
Here is the code I tried,Segmentation fault was the result..
void allocate(int ** universe,int n) // to assign pointer "a" a nXn matrix
{
universe=(int **) calloc(n,sizeof(int *));
...
1
vote
2answers
106 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 ...
1
vote
3answers
58 views
For “int demo[4][2]”,why are all these same in magnitude: &demo[1],demo[1],demo+1,*(demo+1) ?What about type?
Just when I had relaxed thinking I have a fair understanding of pointers in the context of arrays,I have fallen face down again over this following program.I had understood how for an array arr,arr ...
0
votes
2answers
205 views
Allocating memory for a 2d array of pointers wrapped within an struct in C
Let's say I have a struct named 'Foo' and inside of that I have a 2d array of pointers
typedef struct Foo {
Stuff* (*stuff)[16];
} Foo;
I have an initializeFoo function like ...
0
votes
1answer
135 views
pointers to a multidimensional array in classes
I'm trying to get to the bottom of an error, I wonder if you could help please? I'm having a bit of an issue with array pointers at the moment. I have three classes, one parent, and two children so ...
2
votes
5answers
153 views
Segmentation fault on using memset instead of for loops to initialize int**
Here is my code in c++
int** a;
try{
a = new int*[m];
for(int i = 0; i<m;i++)
a[i] = new int[n];
}
...
Right now i am initializing the above using for loops as follows:
for(int i = 0; ...
2
votes
3answers
358 views
How to solve the issue passing an unknown-sized 2D array to a function?
I have a program in which the object array's size is determined during the runtime, so it's dynamically allocated (2D array, read from file). I also have a function which takes these objects as ...
0
votes
1answer
133 views
assigning strtof value into 2D array in C
I'm trying to parse a CSV file into a 2D array in C. I want to make a matrix wit the structure :
typedef struct {
int row;
int col;
float **arr;
int numElements;
} Matrix;
The ...
2
votes
3answers
150 views
2D array to pointers [duplicate]
I've got array: int i[20][30]. What is the fastest way to make int** pointer to use on it?
My friend just wrote function which uses same size arrays and my function is on pointers and I need to pass ...
0
votes
3answers
1k views
C++ Accessing Values at pointer of 2D Array
I need a dynamic 2D array of ints, it will represent a standard matrix. The size and elements are read in from a file at runtime.
Taking direction from other stack posts I've setup my array as ...
0
votes
2answers
293 views
Swap 2d Array Reference in function
I am trying to swap two 2d arrays, old and new. I want to call a function, copyNewToOld, without actually copying the values. I just want the reference to old to point to the location of new, and ...
0
votes
4answers
402 views
create a pointer to a 2D array
I have a
bool array[size][size]
and want to pass a pointer of it to a function to change its value.
void change_to_true(???, int i, int j) { // don't know what type it should be
array[i][j] = 1;
}
...
0
votes
1answer
491 views
How to declare of array of pointers to 2D arrays
I have a list of 2D arrays:
float a[][9] = { ... }
float b[][9] = { ... }
float c[][9] = { ... }
I want to have another array of pointers that point to each of the 2D arrays, like this:
...
0
votes
2answers
112 views
returning a 2D array in c++ using typecasting
int** function()
{
int M[2][2] = {{1,2},{3,4}};
return (int **)M; //is this valid?
}
void anotherFn()
{
int **p = new int*[2];
for(int i = 0; i<2; i++) {
p[i] = new ...
1
vote
2answers
96 views
return a partial struct
I'm attempting to modify several functions to return struct types without changing all of the values. Specifically, I'm trying to resize images in various ways and return the dimensions of the new ...
1
vote
1answer
248 views
C++ 2D array of pointers segmentation fault
I am facing an issue with a 2D array of pointers. It compiles with no errors, however when I try to run the file, all I get is a single line saying I have a segmentation fault.
My header file:
...
2
votes
1answer
174 views
Legal array assignment statements in C [duplicate]
Possible Duplicate:
What is the difference between char s[] and char *s in C?
Difference between char *str = “…” and char str[N] = “…”?
I am a beginner in C programming. I am confused ...
2
votes
3answers
79 views
arrays of pointers to pointers 2d arrays
I'm trying to create a continuous block of memory in one function call that has the first part of the memory as pointer arrays to the other blocks. The function works with an index notation though ...
2
votes
3answers
200 views
Array to functions in c
The normal method I use to pass one-dimensional array to a function is as follows.
#include <stdio.h>
#define ARRAY_SIZE 5
void function(int *ptr_array, int size)
{
int index;
...
1
vote
4answers
4k views
Pointers with two dimensional array
Please consider the following piece of code
#include <stdio.h>
#define ROW_SIZE 2
#define COL_SIZE 2
int main()
{
int a[ROW_SIZE][COL_SIZE]={{1,2},{3,4}};
// Base address:Pointer to the ...
0
votes
1answer
794 views
C: Passing pointers: incompatible pointer type warning
I'm trying to pass a 2d-array (array of strings) to a function in C, but am running into an "incompatible pointer type" warning.
In function ‘main’:
warning: passing argument 1 of ‘addCodonstoHash’ ...
5
votes
3answers
270 views
Please explain the difference
i have a program about 2-D arrays
base adress is 8678
#include<stdio.h>
#include<conio.h>
main()
{
int arr[3][3]={
{83,8,43},
{73,45,6},
...
-4
votes
1answer
2k views
Printing 2D Array using pointers in C
#include "stdio.h"
void main(){
int a[2][2]={1, 2, 3, 4};
int a[2][2]={1, 2, 3, 4};
display(a, 2, 2);
show(a, 2, 2);}
}
display(int *k, int r, int c){
int i, j, *z;
for(i = 0; i < r; i++){
...
0
votes
3answers
507 views
C++ pointer to 2D array
Hi I know there are a lot of similar questions but I've been through them and I can't seem to make my function work. I need to return a pointer to a 2D array. So far I am using this code:
(This code ...
0
votes
1answer
560 views
declaring a 2D array of pointer objects
I'm having a tough time figuring out how to instantiate a 2D array of pointer objects. Here is how I'm doing it:
Pieces* chessBoard[9][9];
When I want to set it to an actual object pointer, I'm ...
2
votes
3answers
198 views
Assigning and Deleting Pointers
Okay, so here's the context. I've been up for almost a day straight now working on the legendary 8-puzzle problem. I have my heuristics down and my A_star algorithm down. We are required by the ...