displayArray Function For c

I am new in c programming and I am studying arrays right now. I saw that unlike java you can't print them automatically by using Arrays.toString() method. I want to write a simple function that prints the array. In the program it asks us the size o...
more »

2017-07-11 14:07 (2) Answers

C: Passing any function to a function

I would like to know how I would go about passing any function to a function, as in a generic function pointer that can take any function whatsoever, The goal of this is to make a destructor system, so basically storing the function and calling it wi...
more »

2017-07-09 21:07 (2) Answers

when should we care about cache missing?

I want to explain my question through a practical problem I met in my project. I am writing a c library( which behaves like a programmable vi editor), and i plan to provide a series of APIs ( more than 20 in total ): void vi_dw(struct vi *vi); void...
more »

2017-07-05 11:07 (1) Answers

Confusion about malloc and calloc function in C

Declaration of malloc function: void *malloc(size_t size); Here, malloc returns void pointer. So, A void function returns nothing, then Why we assign malloc(function call) value to pointer? For example: int *ptr; ptr = malloc(10 * sizeof (*pt...
more »

2017-07-03 12:07 (3) Answers

Pointer Problems and Dynamically allocating Memory

I'm working on an exercise that will eventually turn into a pthread experiment for educational purposes. Here I'm taking a list (the alphabet) and trying to get five lists of numbers that I can feed to a pthread to analyze something. For example, num...
more »

2017-07-02 10:07 (2) Answers

Why quick sort will never have stack overflow?

Assume that a computer system has a heap of 2GB and that the size of the call stack for an application is 1MB. Quicksort is used to sort an array that is stored on the heap (i.e. it is stored in the computer's internal memory not on a file). Assum...
more »

2017-07-01 12:07 (0) Answers

reading string twice? What's the prob? C

In my code I have a menu with 4 options : 1-> am trying to read 2 strings, and then 2-> count the 'e'-s in them, 3-> quit the program, or 4-> print the two strings. int add(char *str1, char *str2){ int res=0; int index=0; for(index=...
more »

2017-06-30 21:06 (2) Answers

return statement in void function in C

In the following program, Why compiler does not gives any error or warning? cc -Wall -pedantic my_program.c code here: #include <stdio.h> void f() { return; // return statement in void function } int main() { f(); ...
more »

2017-06-30 12:06 (2) Answers

How to print cascaded names of functions pointers?

I was working of functions pointers examples and I developed 4 simple functions and assigned them to a function pointer array, then I ran the code and worked for the 4 functions, but then I thought to also print the names of the functions. I learned...
more »

2017-06-30 09:06 (4) Answers

Tree recursion compiles, but crashes on execution

I'm writing a program to traverse a pre-built tree. I don't know anything about the tree structure as far as number of nodes, location of nodes, etc, but I need to traverse all the nodes and sum the values of the nodes. The node is defined as struc...
more »

2017-06-28 22:06 (1) Answers

Calling a 2D array function?

I first apologize if some of you find my problem stupid and easy to solve, but I am a very beginner in "c". My task is to create an inverse of a 3x3 matrix using different functions. What I am trying to do now is to tell the user to input values f...
more »

2017-06-23 08:06 (4) Answers

Risks of adding uint to enum in function call

I have a function that returns a float number: float function(enum value) I then have an enum typedef enum { a = 0, b, c } myenum; I want to do the following: function(a+1); And I wonder if there are any risks other than the risk...
more »

2017-06-20 15:06 (2) Answers

Exchange sort algorithm in c using pointers

I am trying to write an exchange sort in c using pointers, NOT indices; I do not understand why this code does not work: void sort(int a[], int n) { int *i, *j, *temp; int * const end = a + n; for(i = a; i < end - 1; i++) for(j = i + ...
more »

2017-06-19 19:06 (1) Answers

Why malloc can't work with strcpy?

char * removeChar(char * str, char c){ int len = strlen(str); int i = 0; int j = 0; char * copy = malloc(sizeof(char) * (len + 1)); while(i < len){ if(str[i] != c){ copy[j] = str[i]; j++; ...
more »

2017-06-19 17:06 (4) Answers