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 without a specific reason.
405,560
questions
0
votes
0
answers
13
views
K&R recommends the use of int when reading character using getchar()? [duplicate]
The problem is distinguishing the end of the input from valid data. The
solution is that getchar returns a distinctive value when there is no more input,
a value that cannot be confused with any real ...
-1
votes
1
answer
22
views
Populating two arrays from a CSV file with each row containing two words separated by a semicolon
How could I fix my code that populates two separate arrays from a CSV file that contains words separated by semicolons in C?
My CSV file looks something like this:
to meet/encounter;begegnen
to care ...
0
votes
0
answers
22
views
Problem With Adding SFML 2.6.1 To Dev C++ (Linker Error)
I'm trying to add SFML 2.6.1 to Dev C++ (I use Windows 7). I added lib and include to Libraries and C++ Includes in Compiler Options; and added "-lsfml-graphics -lsfml-window -lsfml-system" ...
0
votes
1
answer
58
views
Weird timings when measuring the perfomance of binary search [closed]
Okay, so what is happening here puzzled me for 2 days. Basically, as an activity I was measuring how much time some algorthim takes to execute in its worse, average, and best cases. Until now, I got ...
-4
votes
0
answers
37
views
Question about the address change in dynamic array unexceptionally [closed]
Basically, the program manages storage placed in memory. Each chunk has a header including all the details about the chunk, including size and the next chunk. I create a struct header to store all ...
1
vote
0
answers
23
views
Broken pipe error with Ports between Elixir and C [closed]
I am attempting to write a program in Elixir that connects to a C program via Port and erl_interface. I got the C code up and running and managed to send data through the port as well as decode and ...
0
votes
4
answers
60
views
How does 'long double' occupy 16 bytes / 128 bits of storage when my CPU (X64 ISA)?
I'm a novice C programmer; this might be a naive question to ask but please bear with me. I learnt that the storage size of char, short, int, long, long long, float, double, and long double are ...
0
votes
2
answers
33
views
Is it possible to define a macro that checks if a value falls within value range for any given sequential enum?
Given an enum which is assigned sequentially (i.e. the first value is 0 and the last value is the number of enumerations - 1), we can check if a value is a valid enum value like so:
enum e {FOO, BAR, ...
0
votes
2
answers
67
views
How can i make a C program exit when key Q is pressed?
i am making a counting program, and i want to add a feature that quits the program, but i don't really know how to do it. i have seen examples on how to do it, but all of them are for windows. please ...
0
votes
1
answer
46
views
Why does printing cause the heap break to increase by this much?
I wrote the following program,
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include "rand.h"
int main (int argc, char* argv[]) {
...
1
vote
0
answers
14
views
Does the EVP_KEY created by OSSL_DECODER_CTX_new_for_pkey need to be manually freed?
Does this code (ignoring lack of error handling) leak with OpenSSL 3.0?
EVP_PKEY *pkey = NULL;
BIO *public_key_file = BIO_new_file("public.pem", "r");
OSSL_DECODER_CTX *dctx = ...
1
vote
0
answers
13
views
Clang error: libdnk.a, libunwind.a and libc++.a linkage issues in windows build
I am trying to build an ELF file using the ARM-M4 toolchain version 8.1.0. My C code files compile successfully, but I encounter the following error while linking the object files
[100%] Linking C ...
2
votes
3
answers
69
views
Read is blocked by getc
For the following code:
#include <unistd.h>
#include <stdio.h>
int main()
{
char buf[6];
printf("%c\n", (char)getc(stdin));
int ret = read(STDIN_FILENO, buf, 5);
...
2
votes
1
answer
31
views
LNK2019 unresolved external symbol in function defined in static library
I am trying to compile a driver through the use of cl.exe on Windows 10. It is written in pure C. I am using the Enterprise Windows Driver Kit to provide source files and compiling for X86. I ...
0
votes
1
answer
58
views
In C language, do multiple implicit conversions that occur in an expression have a certain order? [closed]
(My question might be quite long. I would be very grateful if you could read it through.)
I am learning C language by reading the C11 standard. I find that there are quite a lot of implicit ...
1
vote
0
answers
31
views
How can i use functions from libc in NASM 64 bit
im making my own programming language and i wanted to call some functions from libc (es strcat and printf) but im unsure on how to call them correctly(i dont which cpu registry to use and if i have to ...
0
votes
0
answers
14
views
Receiving and Sending J1939 CAN message on Linux in C
I am trying to open a SocketCAN J1939 and receive and send J1939 messages. I am very confused with type "sockaddr_can". This structure has j1939.addr, j1939.pgn, j1939.name etc. When I ...
0
votes
1
answer
57
views
Passing `volatile` buffers to library functions which do not take `volatile`
I have a multi-processor system with a "shared" memory region used for communication. In some cases one of the processors needs to process some considerably large data in the shared memory ...
2
votes
0
answers
67
views
malloc fails even with enough memory
I'm implementing a SkipList for academic purposes in C.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
// ===============================================
// SkipList
// ===...
1
vote
0
answers
38
views
Unable to access server running in k8s pod from WSL host with docker-desktop installation
I'm running docker-desktop with WSL2.0 ubuntu on windows. I created a k8s deployment in the wsl ubuntu host. The deployment has one pod where I'm running a simple server program(runs forever, accepts ...
1
vote
0
answers
41
views
Adding attributes to entire c-file instead of specific function
Hi I was trying to add the attribute __attribute__((section(".protected"))) to my whole c file. My temporary solution was to just give this attribute to main() and put all the variables ...
1
vote
1
answer
38
views
iconv: Invalid argument error when passing struct element
I have a function which converts utf-16 string to utf-8 by using iconv library (ignore "ISO-8859-1" part, my test files all are utf-8 and utf-16). Here is it's code:
char* to_utf8(const ...
3
votes
1
answer
57
views
In R, how and where does the underlying C functions get their argument inputs?
I'm trying to understand what happens at the C level when I call a function in R. For instance, print("Hello, World!") will call UseMethod("print"). From the "table" in ...
0
votes
0
answers
34
views
TCC & CLion errors
I've setup successfully the CLion + TCC enviroment on the windows 10 machine. My colleague asked me for help with that so I shared the CLion project and he:
unpacked the TCC in the right directory,
...
1
vote
0
answers
39
views
How to handle error creating threads in a loop
I'm into the Philosophers project, it is about handling threads and mutexes. For the project I need to create several threads, each thread runs a routine function and accesses shared resources. I ...
1
vote
1
answer
79
views
C serial communication, Why does read() lose some data bytes at high baud rates (e.g., B921600)?
Question:
I am implementing a C program to communicate between two serial ports on the same machine. The setup involves two serial ports connected via a Null Modem adapter, and I am experiencing an ...
0
votes
0
answers
64
views
How do I properly call OpenGL 3.3 functions in Fortran?
For some reason, I am trying to run OpenGL 3.3 in Fortran. I'm having trouble calling glGenBuffers().
When trying to compile a program with the glGenBuffers function, the lnk2019 error occurs. The ...
0
votes
1
answer
27
views
problem with cs50 p-set3 runoff (print winner funtion)
so this is a problem from CS50 Week 3 runoff, when I am running this code I am getting the following error, I cant understand why?
I don't find any problem with the code, so need help from more ...
0
votes
0
answers
64
views
Why, how, and when to write POSIX compatible code? [closed]
Disclaimer: I thought this question was a factual question but SO marked it as opinion based. I re-wrote it below so hopefully people can answer with factual information about CLI tools in C.
I just ...
0
votes
1
answer
37
views
How do I detect when an AIO operation finished without spinning?
In C you might be able to use AIO to do IO in the background without hanging if the IO takes a while, and without the unnecessary creation of threads.
But is there a way I can put a callback function, ...