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 ...
1
vote
1answer
35 views

Console crashes in C during a for loop

So I'm beginning a game in SDL and C, and during the first hours, with only 2 functions and not so many lines, I get a crash of the console. I got a 2D array of a type structure wich contains the ...
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 ...
0
votes
3answers
32 views

Initializing a global 2D array in C from a function

float verticies[14][3]; init_mod(){ verticies = {{-0.5,-0.5, 0.5}, { 0.5,-0.5, 0.5}, {-0.5, 0.5, 0.5}, { 0.5, 0.5, 0.5}, {-0.5, 0.5,-0.5}, { 0.5, 0.5,-0.5}, {-0.5,-0.5,-0.5}, ...
0
votes
4answers
48 views

C: Pass 2D int array

I'm having issues passing a 2d integer array to a function array in C. My task is to scan lines of integers from stdin into a 2d array, and then pass that array off to another function for processing. ...
0
votes
3answers
51 views

Pass a column of 2D array

Let's say I have a 2D array and I want to pass it's i th column to a sort function that takes in a 1D array and sorts it. Can it be done without copying the column to another array in C/C++ language. ...
-1
votes
1answer
29 views

2d array matrix not printing properly

Matrix is not printing properly, Can anyone tell me where I went wrong?? int i , j; int n =0 , m =0; int p =0 , q =0; int matrix1[n][m]; int matrix2[p][q]; ...
-1
votes
2answers
43 views

“assignment makes integer from pointer without a cast” in c

I'm in the late stages of a c program that is a dynamic word search. I get the "warning: assignment makes integer from pointer without a cast [enabled by default]" when I compile these lines: **grid ...
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 ...
0
votes
3answers
65 views

Contiguous memory allocation for 2D array — freeing the memory

I am facing a heap crash during free() when I run this program, but I am successful if I do debug using F10 (in Visual studio 2010). My piece of code: The below code is used to free. Can someone ...
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
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
64 views

Why must I provide a dimension when passing a two-dimensional array to a C function?

I'm not sure if the history tag is relevant, but feel free to add it. I would presume the reason is historical, which is why I suggest this. Why is it that I cannot declare a function signature such ...
0
votes
3answers
43 views

returning 2D array having error, need concept

I tried different methods but eventually got errors. Please give a solution and a brief explanation of the concept. uint8_t **subBytes() { int i,j; uint8_t r,c; uint8_t t[4][4]; ...
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] ...
0
votes
1answer
106 views

String Comparison in C strcmp

I have domain names stored in a 2 dimensional array of char char domainNames[2][4096]= {"www.yahoo.com","java.sun.com"}; and I need to check if a given domain name stored in another array( char ...
0
votes
3answers
80 views

Dynamic allocate 2d array and init it (segmentation fault)

I am learning C and I tried to allocate memory for a 2D array (the dimensions of the array I get them from the user), but I get a segmentation fault after I try to init it. My code is this: #include ...
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?
0
votes
1answer
111 views

C-JNI returning 2D int array as a JobjectArray

So I decided to make a dll import to my java code. What it does is calculating neighbor matrix. The issue is that I have no idea how to return matrix as a jobjectArray. JNIEXPORT jobjectArray ...
1
vote
5answers
159 views

why does this pointer arithmetic on a 2D array work?

I wrote the following code: #include <iostream> using namespace std; int main() { int a[10][10]; for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) ...
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 ?
-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
4answers
86 views

printing a 2d array of string in c

i'm trying to print a 2d array of string as practice(i'm a newbie) with no success i've tried every combination i could think of still nothing i'm sure i'm doing a silly error somewhere i just can't ...
0
votes
1answer
53 views

Compare same words

I'm new in programming in C and I got 2 problems. I have two string, then I need to split them into words and find out if both strings contains same words. I will explain it with my code. Input: "He ...
2
votes
3answers
67 views

Pointers to a 2d array and manual memory management - C

I decided it would be a nice challenge to build a library to handle all kinds of matrix calculations, in pure C. Now, even though I have some pretty good experience with Objective-C and Cocoa, my ...
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] ...
1
vote
2answers
275 views

Sort a two-dimensional array just like a one-dimensional array in C?

I want to sort a two-dimensional array like this: 4 2 5 1 3 7 6 9 8 to obtain like this: 1 2 3 4 5 6 7 8 9 using language C. A couple of options for tackling this problem could include: ...
0
votes
1answer
63 views

I get segmentation fault when I try to insert new row into 2D-Array using realloc

When ever the program finds a row in witch the first element's last number and the last element's last number divide by 2, then it should add other row to the matrix. I need to do this using dynamic ...
0
votes
0answers
32 views

A function that takes in a pointer for an array outputs code for the position of a polygon

Here is a section of my code: float wallSize = 0.025; short int gMtrx[200][200]={{1}}; void filler(short int *gMtrx) { //--for loop--: scrolls through the matrix //for each value of 1, ...
0
votes
3answers
57 views

Calculate only the first dimension elements in a two dimension array?

I have a two dimension array that stores coordinates (xy) int arr[3][3]. How do I do calculations to only one of the dimensions in the array? If I am interested in the average of the x coordinates I ...
0
votes
2answers
92 views

How to input multi-word string in C

I have this program. I want to input multi-word strings in a 2-D array. But instead of input whole string in first array of 2-D array this program inputs the first three words of my String in the ...
0
votes
2answers
64 views

how to increase the size of 2d char array element size in c

char symbol[100][100]; for(i=0;i<n;i++) { printf("enter the symbol\n"); scanf("%s",&symbol[0][i]); } strncat(&symbol[0][0],"1",1); output for ex:- in symbol[0][0] ...
-2
votes
1answer
39 views

append character to a two dimensional array value in c

char str1[50][50]; char str2[40]="1"; char str3[40]; for(i=0;i<5;i++) { printf("enter the value\n"); scanf("%c",&str1[0][i]); //entered values in zeroth row only ...
0
votes
2answers
55 views

C library to extract statistics from a 2 dimensional data array / image [on hold]

Is there a library for C to extract statistical measures (mean, variance, i.e. n^th moments) from 2 dimensional data? Something like double sigmaX(double *matrix) { double ...
-1
votes
2answers
215 views

Calculating Standard Deviation for a 2D Array in C

Here's my code, it is supposed to calculate the standard deviation of the randomly generated array that fillArray populates. stdDev is supposed to calculate the standard deviation. otherStats is ...
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 ...
1
vote
3answers
1k views

Dynamically allocated 2 dimensional array

I am trying to build two dimensional array by dynamically allocating. My question is that is it possible that its first dimension would take 100 values, then second dimension would take variable ...
0
votes
2answers
82 views

Issues with 2D array and strings

I am trying to create a program that reads a file called words.dat that contains a word-list of 20 words separated by white-space and tells the number of matched words. However the word cannot be any ...
0
votes
1answer
48 views

How to identify if each random number is hit error

so I was writing a program where I need to generate a set of random numbers from 1 to a certain number that the user enters. Then identify the approximate probability that each number from 1 to N was ...
0
votes
2answers
104 views

2D array function logic

I created this program that scans a 2D array for vertical and horizontal pairs, where row = 20 and column = 30 , and then displays the output. I think I may have messed up my logic in Functions 2 ...
1
vote
1answer
63 views

2D array using a function to scan for pairs

I created this function that scans a 2D array for vertical pairs, where row = 20 and column = 30. To clarify random characters from A to Z are stored in each of the array's elements. char function3 ...
0
votes
2answers
118 views

Allocating memory dynamically to a 2-d array of strings

int ReadNames(char ***Names, int *r,int *c) { int i, j, k; char name[100]; printf("Number of Rows: "); scanf("%d", r); printf("Number of Columns: "); scanf("%d", c); Names=(char ...
0
votes
1answer
104 views

C. 2D array crossword like program [closed]

I have Created a 2D array of characters that has 20 rows and 30 columns (accomplished in main( ) ). I then populated each element of the 2D array with a random upper-case character and displayed that ...
0
votes
1answer
148 views

Using 2D Arrays in C

Ok so I created a program that successfully creates a 2D array and stores random numbers in the array and determines the highest, lowest, and average of the random numbers created using arrays and for ...
0
votes
3answers
82 views

Unusual warning when deallocating memory of a 2D array in C

I'm trying to free the memory I allocated for my 2D array. The code is working fine, but I always have warnings when compiling. I tried 2 different methods but each time, a new warning appears. ...
0
votes
1answer
120 views

How to find number of rows in dynamic 2D char array in C?

I have an input function like : int func(char* s[]) { // return number of rows in the character array s } where the char array s is provided randomly as for eg: {"sdadd", "dsdsd", "dsffsf", ...
0
votes
1answer
74 views

Trouble Resizing a 2D Array in C

I have a project where I create a 2D char array that stores words, with the option to add more words, and then resize the array when necessary. I'm getting a variety of errors as I try to play with it ...

15 30 50 per page