Questions tagged [c]

C is a general-purpose programming language used for system programming (OS and embedded), libraries, games and cross-platform. This tag should be used with general questions concerning the C language, as defined in the ISO 9899 standard (the latest version, 9899:2018, unless otherwise specified — also tag version-specific requests with c89, c99, c11, etc). C is distinct from C++ and it should not be combined with the C++ tag absent a rational reason.

Filter by
Sorted by
Tagged with
0
votes
0answers
19 views

libgnuutils memory leak when threading

I'm doing some threading and I've been getting this memory leak. The threads run through then join at the end. I'm new to threading so I don't really know what the library error is shown by Valgrind ...
-5
votes
1answer
64 views

Get hidden characters of line feed in C

I have a work to do which I need to make a linux2dos function. Basically I have to find all line feeds (0X0A) and put carriage return before it (0X0D). As LFs and CRs are hidden in the file I don't ...
0
votes
0answers
26 views

How to insure 'scanf' got int and not double [duplicate]

I'm new in c and I want to scanf an int. To do it I use scanf("%d", number). Here is my problem: i want to make sure I got an int and not a double. For example, if got 1.0 , I want to print "got a ...
0
votes
1answer
31 views

What is the time complexity(theta) of evaluating an expression using parser module in Python3?

I want to know the algorithm or the time complexity that the parser module in Python3 uses in order to eval the expressions. This is my code: import random import parser equation_ = '(x**3 + 5*(x**...
0
votes
0answers
34 views

Count Sort in C - problem with output and count_array

I am trying to implement a count sort algorithm in C for uni. The task was pretty easy because we were given pseudocode to translate into c-code. But somehow my count_array and output_array go crazy. ...
1
vote
1answer
65 views

makefile tries to compile itself

Can someone help to solve this problem. When I try to do make my makefile does this. `echo ./src/main.c ./src/main.c gcc -c -g -Iinclude src/main.c gcc Makefile.o -o Makefile clang: error: no ...
0
votes
0answers
37 views

How to shrink pointers (linked with GSL)?

I have a problem with my code when I was trying to shrink the allocated memory. The result showed : creating matrix reallocating matrix (expanding) defining GSL matrix in new matrix reallocating ...
1
vote
1answer
31 views

Sorting and Analyzing Arrays In C

I made a little dice game where I should get Grand if I throw 5 times the same number and a Poker if I throw 4 times the same number. My problem is that my code only work with "1" and "2" if I try to ...
-1
votes
1answer
32 views

This code works for maze but i dont know how it works. Can somebody explain how does it work that “ if” code block?

#include<stdio.h> int main() { int x = 0, y = 0; int maze1[4][4] = { { 1, 0, 0, 0 }, { 1, 1, 1, 1 }, { 0, 1, 0, 0 }, { 1, 1, 1, 1}}; // The maze which is should be solved. int ...
0
votes
2answers
22 views

Having trouble using sigaction with a timer in C

This is my code. As you can see it is very simple. I want the program print dots until it catches SIGPROF signal. But my program seems like it's not working. How can I fix it? void handler(int code) {...
1
vote
1answer
29 views

Dynamic Array of Strings Causes Segfault

I wrote some code to create a dynamic array of strings which is automatically resized once full. Even though there seems to be no issue inserting elements in it, I get a segfault when trying to print ...
-1
votes
2answers
30 views

Print Fahrenheit-Celsius Table in Reverse

I have a question how to solve this objective. "Modify the temperature conversion program to print the table in reverse order, that is from 300 degrees t 0." THe Program is written in C. #include &...
0
votes
1answer
33 views

How do I solve Segmentation Fault (Core Dump) error in my CPU Scheduling Simulation program in C?

I am very new to C and am getting a Segmentation Error when trying to run the following code (which is a program that originally simulated an FCFS scheduling algorithm, but I had to modify to simulate ...
1
vote
0answers
42 views

Inserting “marker” instructions into assembly without GCC reordering them

For purposes of doing performance analysis it is useful to be able to tell which line of C code goes with which line of generated assembly code. This can be very difficult once a sufficient number of ...
-3
votes
0answers
65 views

passing raw pointer from C++ to C API [on hold]

I have to interface with C API using C++ objects. The C API has a interface function: int foo(const int* p); At C++ object the function implemented is int fooObj(std::shared_ptr<const int> ...
0
votes
1answer
44 views

MakeFile - Avoid certain files when a target is passed

I am trying to create a target which avoids certain c file. I am doing so because certain file are not compatible and want to avoid them during the build. Bellow is the approach I am using but getting ...
2
votes
1answer
90 views

Is it reasonable that a static array is 700 times slower in this particular case?

I must admit that I'm not very experienced in C. At my attempt to port my Perl module LCS::BV to C and tune the code I got in one session a surprising rate of 5 G iterations per second (compared to 12 ...
0
votes
1answer
20 views

Get 2 consecutives frames with av_read_frame()

I am working with rtmp and ffmpeg/libav. I have a clip with a fps of 60 fps where it is made of 2 consecutive video frames and 1 audio frame. The 2 consecutive frames correspond to left and right ...
1
vote
0answers
78 views

Produce all possible errors with Clang/Ninja

I am compiling a fairly large library with many outside dependencies that I need to pull in. Each time I attempt a compilation I get a new error about a missing header file. I then have to go and ...
0
votes
1answer
65 views

Difference between *[] and ** in this code block?

First code block (*arr[]) char *arr[] = {"abc", "def"}; int main(void) { int arr_len = sizeof(arr) / sizeof(*arr); printf("%d\n", arr_len); return 0; } Second code block (**arr) char *...
0
votes
1answer
22 views

GLUT menu creates problems with OpenGL game?

I am trying to make a 2D game with GLUT & OpenGL. I am using a menu with the click of right mouse button its a pop up, menu works fine but in order to reload my drawing function I have to click ...
0
votes
0answers
25 views

Cython buildable (Python Binded) C code to download file via HTTP (REST API)

I have been googling and searching some good example(s) and so far somewhat closest was this one: Architecting a RESTFul C++ api to interface with Python In a nutshell: Essentially, I am building .so ...
0
votes
0answers
20 views

AVR Internal eeprom reading issue

I am using the internal EEPROM of atmega8A using avr's EEPROM library. My code looks like this #define EEPROM_ADDR 0x0A int main(void) { _delay_ms(2000); LED_Initialize(); vBlink_Led(...
0
votes
0answers
47 views

My code is writing to a file wrong using fseek()

So i'm trying to write to a file line based on a variable called index which is basically the line number of the file. For some reason the fseek function is not working. It works for index=0 but not ...
1
vote
1answer
34 views

Why stat(2) on location /proc/<pid>/<files> always give a empty size

It seems that I can't cast stat(2) or fstat(2) on the (pseudo-)file under /proc to get it size. file: test.c #include <unistd.h> #include <sys/stat.h> #include <stdio.h> int main(...
0
votes
1answer
43 views

Create an array based on lines in a file

Firstly, I don't post here that often. So apologies if this is out of place. I moderate some forums so I understand why you would find it frustrating if this is in the wrong place or answered 1000 ...
0
votes
0answers
34 views

How to create a new node using the following structs?

I am trying to make an open doubly list. How shall I initialize/create a new node, with the given structs ? Note that I can`t change function parameters, nor the structs. The structs given to us are ...
0
votes
1answer
44 views

memcpy long long int (casting to char*) into char array

I was trying to split a long long into 8 character. Which the first 8 bits represent the first character while the next represent the second...etc. However, I was using two methods. First , I shift ...
1
vote
1answer
38 views

Programatically populate a uint8_t array

I have a uint8_t array which should look like this . uint8_t code[1000] = {0x66, 0xba, 0xf8, 0x03} Now I cant hard code values in that array instead , I need to insert them one by one from char ...
0
votes
2answers
37 views

Allocate the resource of some threads to a global resource such that there is no concurrency(using only mutexes)

The summary of the problem is the following: Given a global resource of size N and M threads with their resource size of Xi (i=1,M) , syncronize the threads such that a thread is allocated,it does its ...
0
votes
0answers
10 views

Setting PHC for Linux Device Driver

I recently upraged my linux from 3.10 to 4.4.8 After doing this I have run into an issue with my NIC drivers. I have have two NIC drivers (eth1, eth2) and their respective PHC's ptp0, ptp1 After ...
1
vote
1answer
38 views

How can I use the result from a function as a parameter to another function in C?

In a function that returns void and has no parameters I want to use two other functions (unfortunately I cannot modify that). The first of these functions calculates the result of an int and I want to ...
1
vote
1answer
14 views

The display function doesn't execute , the head value keeps getting set to null so the display function keeps printing empty

#include <stdlib.h> #include <stdio.h> struct node *create(int num); void display(void); //linked list node creation struct node { int data ; struct ...
-1
votes
2answers
40 views

need explanation on math calculation done by using c

I found following code on c #include<stdio.h> int main(){ int a; a=015 + 0x71 +5; printf("%d",a); return 0; } when i compile it, it gives 131 as the answer. but i ...
2
votes
1answer
45 views

Why using dup(1) before close(1), open(“/dev/stdout”, O_WRONLY) results in “No such file”?

Problem is same as the title, the OS is linux. I've tried a few examples. dup(1); close(1); int fd = open("/dev/stdout", O_WRONLY); This caused a "/dev/stdout No such file" error. I thought a file ...
-7
votes
0answers
30 views

invalid types 'int[int]' for array subscript in Dev c++ while doing heapify in c

Whenever I'm going to update the binary tree using right, left and max variable in the array that is visible in the highlighted portion Dev c++ ide throwing an error of invalid types 'int[int]' for ...
0
votes
1answer
46 views

C preprocessor macro to create lookup table

I have a lookup table which links all my 'two char commands' e.g. AA, AB, SS, to their corresponding function addresses in alphabetical order of the first char. The row, i.e. branch, in command_list ...
1
vote
0answers
36 views

C library linkage fail with C++

I'm using ESP32 microcontroller (C++) and trying to use "tinyexpr" library (C). I trying to link C library in my .cpp file but even with extern "C" {}, link can't completed. However, when I change my ...
0
votes
2answers
32 views

Why does struct memory initalize with random characters? (Embedded)

Using MCUXpresso with NXP MKL02Z16VFM4 for reference. When I declare a struct like so typedef struct { uint8_t DATA :8; } myStruct; myStruct xxx __attribute__ ((section ("xyz"))); the ...
0
votes
1answer
39 views

OpenSSL C Cryptopals Challenge7

I have been trying to learn OpenSSL C API. I found the interesting cryptopals challenges page and wanted to try some easy challenge. I took challenge 7, AES ECB: https://cryptopals.com/sets/1/...
2
votes
0answers
103 views

Why a redundant indirect addressing makes program to run faster on x86 CPUs? [duplicate]

First let me show a seemingly very silly question. Assuming that the compiler does not optimize the code, which of the following runs faster? // Let's call it "direct version" int a = 1, b = 1; for (...
0
votes
1answer
29 views

Parent process to monitore and fork new child processes depending on exit status

I've created the below code: int main(int argc, char *argv[]) { int i, n, N; pid_t pid; int status; N = atoi(argv[1]); for(i = 0; i < N; i++) { ...
0
votes
1answer
78 views

How to get only the return value of a function in c?

I declare a function with both printf in the body and a return value,how can i only get the return value without printf the things inside the body(I want to use 1 function for both things: printf and ...
0
votes
0answers
14 views

KDevelop function deprecation warnings

I'm using g_str_to_ascii() function from glib library in KDevelop project. The function was added in glib 2.40 and I'm using even newer version of that library, but it's being marked by app as ...
0
votes
0answers
24 views

Execution of mingw32-g++ failed

recently I have installed codeblocks on my new pc. But I failed to run any code. even a printf code! it is showing " it seems that this file is not built yet. do you want to build it now?". if yes it ...
5
votes
1answer
40 views

Why is STDIN not propagated to child process of different process group?

Below is the source of a program that executes cat: #include <signal.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> int main() { pid_t pid = fork(); if (!...
0
votes
0answers
31 views

accessing char* or char array in struct C

ok im having a problem i cant figure out. i have a struct in header file. typedef struct client_t{ char cName[MAX_BRNAME]; char cLname[MAX_BRNAME]; int id; int clientBrNum; int accNum; ...
0
votes
1answer
31 views

Modify a character pointer string array (char * string[])

I've been giving an... interesting... task. I've been asked to modify a character array using a pointer. I'm aware that: *char = "something"; //is a literal and cannot be modified. char[] = "...
1
vote
2answers
40 views

passing array address in a function and returninf a pointer

so i am getting some kind of error , that after my array input the code doesnt run . i wanted to see if my method is wrong for inputting an array address in as a function parameter and then using ...
1
vote
0answers
40 views

Use chdir to change current working directory

I'm creating a program wich is like an "shell interpreter" but in C, in the main program called "Bash" if i write in command line "change NAME" it creates a fork and executes an execlp to call a ...