Category "c"

Cygwin: C standard library does not support TIME_UTC and timespec_get?

Sample code (t667c.c, taken from here): #include <stdio.h> #include <time.h> int main(void) { struct timespec ts; timespec_get(&ts, TIM

Optimal Selection for minimum total sum

This is a problem from competitive programmer's handbook: We are given the prices of k products over n days, and we want to buy each product exactly once. Howev

How to use compile GTK in C on Mac OS

I'm getting started in c and would like to create GUI, so I tied using GTK. I followed the tutorial they gave on https://www.gtk.org/docs/getting-started/hello-

Input: a2b3c4 and Output: aabbbcccc

The code I've written is not producing any output. It just takes the string as an input: #include<stdio.h> #include<conio.h> #include<string.h&g

How can I correctly display all the elements of 2D array that have even neighbors?

I wrote a program that finds and displays all the elements in the 2D array, which have all neighbors(left, top, right, bottom) - even. I tried to put in an if,

How can I safely add and clamp a signed integer in C?

I have a value, of type signed int, which is always clamped between, for example, ±1073741824 (2^30). I should be able to safely add or subtract any arbi

How to detect the 'service stop' command in Linux

I'm writing a C application to drive a LED strip on a Linux machine: the application listens on a TCP socket port to receive commands. If the connection is term

Get kernel symbol name in Golang

I’m trying to use bpf_get_stackid in the eBPF to query the kernel stack with the flag BPF_F_FAST_STACK_CMP. In the stacks map(BPF_MAP_TYPE_STACK_TRACE typ

Copying a certain number of characters from one pointer to another

I have a source pointer (pSource) and a goal pointer (pGoal). I also have a number of characters (n) that need to be copied to the pGoal from pSource. I thought

Cmocka - should we all be creating one executable per test for isolating static variables?

Failure Given the following cmocka test with a static variable in a dependency: main.c #include <stdarg.h> #include <stddef.h> #include <setjmp.h

How can I get a string returned from a function executed from a byte array?

I have a working C program that has the simple function that returns a d character encoded in a byte array. char foo() { return 'd'; } char byte_array[] = {0

On Windows MSVC, is it possible to merge some .obj into one .obj? If yes, how should I do that?

For example, there is three object files a.obj b.obj c.obj just compiled out with cl, and it is desired to combine them into one combined.obj. A comment of an S

How can I get a string returned from a function executed from a byte array?

I have a working C program that has the simple function that returns a d character encoded in a byte array. char foo() { return 'd'; } char byte_array[] = {0

How to use malloc to assign large two-dimensional arrays in C

I know a very large two-dimensional arrays in C needs a long identifier for the variable type when assigning memory to the array to avoid stack overflow errors

How to use malloc to assign large two-dimensional arrays in C

I know a very large two-dimensional arrays in C needs a long identifier for the variable type when assigning memory to the array to avoid stack overflow errors

libsox: record from default microphone

I need to open the default audio capture device and start recording. libsox seems to be a nice cross-platform solution. Using the binary frontend, I can just re

format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘int *’

Each time I submit a program on hackerrank the following error occurs. solution.c: In function ‘main’: solution.c:22:14: warning: format ‘%d

Pass char* array from c dll to python

I have simple dll with function which taks callback as parameter and calls it sometimes passing unsigned char* array. I want to use it in python. Here is dll so

strdupa() implementation for Visual C

I am trying to port a C (not C++) program from GCC to Visual Studio. The GCC specific function strdupa() is widely used in this program. Is there any way to imp

Python's C extension with more than one header

I have been updating a Python package developed in Python 2.7, so far so good until I got to the C extensions. My C (plib.c) file imports the classes below: #in