Dynamically allocating array of structs C

I'm trying to make an array of structs in c, but I can't make it work. When I try to run it, the program crashes. typedef struct{ char name[20]; char manufacturer[20]; unsigned int price; } product; unsigned int stringToNr(char *numbers...
more »

2017-01-05 22:01 (1) Answers

Pointer to Array in C

How can you interpret the following line of code? int (*arrayABC)[10]; In my textbook, it says that we have a pointer to a pointer to the 0th element of an integer array. However, I don't quite understand this. My interpretation: We have some va...
more »

2017-01-04 22:01 (3) Answers

De-referencing char pointer run-time error

Why does the below code cause a run-time crash? The code itself is not very useful, but , by creating a pointer to a char pointer and pointing to string literals in main, passing this pointer to my function and trying to read the strings causes pro...
more »

2017-01-04 16:01 (1) Answers

Cast "pointer to const" to "pointer to const VLA"

In this snippet, a pointer to VLA is used for easier access to a big lookup table : #pragma GCC diagnostic warning "-Wcast-qual" char lookup(int a, int b, int c, char const *raw, int x, int y, int z) { typedef char const (*DATA_PTR)[a][b][c]; ...
more »

2016-12-30 22:12 (1) Answers

Sprintf crashing my program

I am just tryng to use sprintf to concatenate some strings but I had this problem, I don't understand why my program is crashing using sprintf in C. Why this code runs? #include <stdio.h> #include <stdlib.h> int main() { char...
more »

2016-12-23 23:12 (2) Answers

Function pointer in swift

I'm following this tutorial, especially I have problems to convert this function in Swift language: - (id)init { CFRunLoopSourceContext context = {0, self, NULL, NULL, NULL, NULL, NULL, &RunLoopSourceS...
more »

2016-12-23 15:12 (1) Answers

Dynamic allocation of array issue C

To be clear, my code works perfectly. The issue that concerns me is that i am unsure of my array allocation type. My task is rather simple: i am required to do some operations within a dynamically allocated array. Yet, the values are already given ...
more »

2016-12-21 16:12 (3) Answers

Array as function with arguments?

I'm trying to learn c, so I tried reading some source code. But I have no idea what this might mean: static const char*(*const functab[])(void)={ ram,date }; The first part, static const char* is fine, as it seems to be a function (has a...
more »

2016-12-13 07:12 (3) Answers

Why does this swap work and the other doesn't

I was helping my friend with an assignment and it has been a while since I've used C so I cannot find why this works but the first code works and the second one doesn't. This isn't for the assignment since we figured it out but I want to know why thi...
more »

2016-12-03 05:12 (4) Answers

perl6 array assignment: pointer or copy?

In perl6, I want to assign an array to another array and have the resulting array be distinct entity, but it seems neither direct assignment nor cloning can do what I want. Is there a way to copy array over with one expression instead of writing a lo...
more »

2016-11-30 00:11 (1) Answers

access pointer to double array

I have these structs: typedef struct { char *start; char *loops; char *tolerance; double *numbers; } configuration; typedef struct { bool help; bool debug; const char *configFile; const char *inputFile; const ch...
more »

2016-11-27 14:11 (1) Answers

int main(int carg, const char **varg) {

I have the following function: int func(int carg, const char **varg) { //code ... } My understanding is the following: varg is a pointer to a second pointer. This second pointer points to a char. This char is ... either: a single char (1st...
more »

2016-11-26 16:11 (1) Answers

Array address when copying variables

I want to explore something about how the memory is allocated when we try to copy a variable. I did some tests and this one confuses me: func testArrayAddress() { var a [3]int b := a fmt.Printf("address of a %p and of b %p \n", &(a[0...
more »

2016-11-23 11:11 (1) Answers