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.

0
votes
0answers
16 views

Passing stack to a function without allocating the stack [duplicate]

I shouldn't suppose to change the main function. I allocate and fill the stack in another function and when I try to reach in main function, it gave me segmentation fault. I try to allocate the ...
0
votes
0answers
13 views

Errors encountered during linking - undefined symbols when putting them to one of the functions

I have my code in one file, where necessary includes are attached, and I have this weird problem - I have one overloaded function with 3 specializations of it. Let's call it void a(int x, int y); ...
2
votes
0answers
16 views

how to fix this code so that it can test the integers present next to the character?

Given a string containing alphanumeric characters, calculate the sum of all numbers present in the string. The problem with my code is that it displays the integers present before the characters, but ...
-1
votes
1answer
21 views

Segmentation fault: 11 in a program of multithread in C using pthread library

I need to make a program using the pthread C library to work with threads. The text of the task says: There is a corridor that has a single lane for two directions and there are two types of employees ...
3
votes
1answer
67 views

var been changed to 1 with “if (var = 0 || var == 0)” statement [duplicate]

int xx = 0; if(xx = 0 || xx == 0) printf("4"); // if(TRUE||TRUE) then printf("4") if(xx == 0) printf("5"); //xx been changed to 1?? printf("6\n"); I thought the output will be 456, but the output is ...
0
votes
0answers
7 views

How to integrate/use C API libhdfs in Visual Studio C application?

I want to write a C program within Visual Studio 2017 which writes some random integer values into HDFS (Hadoop Cluster). It should work like this: 1. create a csv file and then every second: 2. ...
0
votes
0answers
34 views

how to specify gcc manually where run configure command

I want to compile GNU make in Mac Mojave,and the OS default c compiler is clang.when I run: ./configure The output is : dolphins-MacBook-Air:make-3.82 dolphin$ ./configure checking for a BSD-...
-1
votes
1answer
40 views

Why does json data contain extra characters

In the code below, when "data" is printed with: Display_printf(display, 0, 0, "score received: %.*s\n", data); the json data is printed correctly: {"zip":97306,"score":130} However, when I do this:...
0
votes
1answer
52 views

How to unsplit a strtok string in C?

I scanned in a text file and have split the string using strtok. The delimiter was all the punctuation characters. I'd like to now unsplit the file so it reverts back to its original state. Is there a ...
0
votes
0answers
24 views

Parallelizing MPI code in function called from main

I have a serial code in C, that I want to parallelize using MPI, but I want to parallelize a region of the code that is not in main, it is in another function. For example: main(){ int a int b ...
6
votes
1answer
145 views

Why does `assert` macro have value even with `NDEBUG`?

Environment: $ g++ --version g++ (Ubuntu 7.4.0-1ubuntu1~18.04) 7.4.0 It is known that function-like macro assert for debugging can be disabled with NDEBUG defined before the include of assert.h (...
0
votes
0answers
31 views

FIFO implementing system of processes

I am trying to learn processes in C and I thiiink I understood the logic of pipe, but can't understand fifo, even if I read a lot about it. I recently made a program using pipe that takes a string ...
-3
votes
1answer
31 views

Need help executing binary file on bash terminal with -wall -pedantic -ansi flags

Cannot execute program on Visual Studio Code terminal on Windows with -Wall -pedantic -ansi flags. The program for assignment right now is just a simple "Hello World" main in C with a struct I've ...
1
vote
1answer
42 views

i have a problem with assigning a letter to char variable of a struct using function

I'm trying to assign a letter to a char variable of a struct but I'm getting garbage output, I don't know why such a simple code doesn't work. I couldn't find any answers on the internet I've already ...
2
votes
2answers
37 views

Comparing two files for matching lines in C Programming

I am writing a program to compare two files. If matching lines occur then the program will continue to do some task. My second file has only one line and the first file has several lines Contents of ...
0
votes
0answers
22 views

why Macro function,ListView_GetSelectedColumn(),doesn't work? it returns nothing

I am trying to get the selected column index of the ListView control, but the macro function ListView_GetSelectedColumn returns ZERO, no matter how I click. a = ListView_GetSelectedCount(lpNmhdr->...
0
votes
1answer
31 views

How do I make this code output “After swapping: 10, 5”?

So I'm new to programming. And I found this code from Quora when searching about different uses of void in C. I first assumed it would have a result of: "Before swapping: 5, 10 After swapping: 10, 5"...
0
votes
1answer
22 views

Why does HMAC+EVP_sha256 return a different value than openssl for some hashes

When trying to generate HMAC+SHA256 signatures, for some payloads, I get a different result from openssl command line than openssl lib. This is to try and generate a v4 signature for AWS. I am able ...
0
votes
1answer
43 views

What is the difference between O1 and Os?

May I know what is the difference between O1 and Os? I only the firmware size compiled by Os is smaller than O1. However, what is the different in performance wise? Would it has much different?
2
votes
3answers
30 views

Libgcrypt in C returning 42

I would like to preface this with, I am new to C and especially using a lib as large as libgcrypt, so if it is something incredibly simple please be understanding. So, I have been trying to just ...
0
votes
2answers
25 views

How to write data into an offset which is not 512*n bytes using linux native AIO?

I'm writing some app like Bittorrent client to download file from net and write it to local file. I will get partial data and write to the file. For example, I will download a 1GB file, I will get ...
2
votes
1answer
31 views

C Ring Buffer Shared Memory Semaphore ReadPointer WritePointer Not Right

I want to build a File Copier using Reader-Writer Synchronization Paradigm. The Writer initializes the both of the Mutexes. The FullMutex is denoting how many Buffers are available to Write and the ...
1
vote
2answers
34 views

Read Write to Memory space

I am trying to write a Signed Double number to memory and read back the same, reading back is redundant as it is just to verify if the correct data is in the memory before I trigger the PL (...
0
votes
1answer
21 views

How to read just a line with an unknown quantity of ints from a text file onto an array (in C) [duplicate]

I'm trying to read a matrix from a .csr file (not exactly .csr, but based on the .csr format). The first line contains the dimensions of the matrix (x,y). The following line has an unknown number of ...
0
votes
0answers
22 views

C Reader Writer Mutexes for a Copying a File using Shared Memory and Ring Buffer

I want to build a File Copier using Reader-Writer Synchronization Paradigm. The Writer initializes the both of the Mutexes. The FullMutex is denoting how many Buffers are available to Write and the ...
-4
votes
0answers
16 views

In C, implementation of Prefix to Postfix using linked list based stack, why program is stopping?

// There is a program stopping problem. // This is a C program to implement prefix to postfix conversion using linked list based stack implementation. Stack was working but, I don't know why ...
0
votes
0answers
30 views

Understanding Linked List Hash Table Implementation

/* a bucket is a linked list, each of whose entries contains a string and its hash */ typedef struct bucket bucket; struct bucket { char *string; unsigned long int hash; bucket *next; }; /* By ...
-1
votes
0answers
23 views

C FILE (Socket) blocking thread

I'm wanting to read the request I send from a server. I receive the full request, but after I get all the data, it blocks the program from continuing. I'm using FILE *s for this programming ...
1
vote
0answers
24 views

How correctly reassign pointer to array Matlab Coder?

I have the following code: add.h: #ifndef ADD_H #define ADD_H void add(double **a, double **b); #endif add.c: #include "add.h" #include <stdlib.h> #include <stdio.h> void add(double ...
1
vote
0answers
33 views

gcc - modulo calculates wrong results [duplicate]

While debugging my C code I've noticed that the modulo operator does not calculate the right results. I've separated the code into a single file, but no success... What's going on here? My system: $ ...
0
votes
3answers
69 views

Find least common multiple of multiple numbers

The goal of this program is to find the smallest number that can be divided by the numbers 1 to 20 without any remainders. The code is working but it takes 33 seconds. Can I improve it so that it can ...
0
votes
0answers
7 views

libcoap several subscriptions from one client

I am stuck with such problem. I have a coap server, which provide several resources to observe. If I observe different resources with standard coap-client example, run in different windows, it's ok. ...
0
votes
1answer
28 views

How to check every single character of a command line argument? Caesar PSET2

I need to check if inside the command line argument there is a non digit character. For example: ./problem 20x should print out "Not a digit" since it contains an x. My code doesn't seem to loop ...
0
votes
1answer
20 views

C: Why won't the global variables in my library update? (Using ALSA Lib)

Preface: I have looked at the other answers, and I believe this is a different type of issue. It's probably pointer related, but none of the other answers helped. I also may just be missing something. ...
0
votes
0answers
17 views

what is using 20 Byte in a bitmap file?

the bitmap size is 10px in 10px it must be 354 B 54 B=>header 300 B=>Pixel array but it is 374 B and when i calculate the size for bit array overflow happened what is using 20 B? and how can i ...
0
votes
2answers
27 views

Need Suggestion while handle huge pipe data

I'm practicing C code with pipe system call, it works well with small chunks of data. but as the data goes beyond the pipe capacity, dead lock occurs. My test system is Debian Sid, but i believe it ...
1
vote
1answer
19 views

Building APT on macOS (I already did most of port) but getting error “use of undeclared identifier 'GetSrvRecords'”

I am building APT for macOS, I already did most of patches and added some compatibility headers I ported from Linux to macOS all, but I have been encountering the problem at the "15%" of the make ...
0
votes
1answer
28 views

What is the proper way to send an AT command with termios and get the reply

I am using Termios in an (ressource constrained) embedded Linux platform (in C) to send commands and receive data from various tty peripherals (CP2102 USB-UART). Apparently there are various ways to ...
0
votes
1answer
32 views

c language pointer Segmentation fault [duplicate]

Segmentation fault. I get the error when I try to run code in C. I am not getting errors in similar instances when using pointer. #include<stdio.h> #include<stdlib.h> int mult(int *w, ...
2
votes
2answers
34 views

What does toascii do?

What does the function toascii() do? Is there any practical use for it? Note: This is not about the Windows function ToAscii.
-2
votes
0answers
21 views

rpn calculator program in c

I have an assignment,that asks me to create a program that scans a string character by character and if the character is a digit,the digit is put in a stack,but if it's an opperand,then 2 elements are ...
0
votes
1answer
14 views

Kernel Module make file errors

So I am trying to build a simple first kernel module in arch linux but I am getting an error with my make file I tried find the kernel headers for my uname -r but no luck obj-m += Test.c KIDR = /usr/...
0
votes
0answers
28 views

Linux Kernel Driver Development - How to write to device

I am learning Kernel dev for Linux and I always choose a project to learn development . I am wanting to make a driver that will take in input that is written to it and log it or echo it. I.E echo "...
-1
votes
2answers
101 views

Why would someone use int instead of bool data type?

Recently I saw in one project where they typedef int as BOOL and used it in place of bool. Does doing so provides any advantages? typedef int BOOL;
0
votes
1answer
44 views

transform a triangle and sort them in C

Given a triangle, I have to transform a triangle into another in the following way: rotate a given angle the vertex with respect to the origin, and then applied a homothety with respect to the origin. ...
-2
votes
0answers
37 views

What its wrong with my code ? It wont run correctly [on hold]

the point is to read a charackter from the user and to push it in the stack if it is a digit. If it is an operand it needs to take the two last elements of the strack and do the math , depending on ...
2
votes
2answers
89 views

Why are global variables in x86-64 accessed relative to the instruction pointer?

I have tried to compile c code to assembly code using gcc -S -fasm foo.c. The c code declare global variable and variable in the main function as shown below: int y=6; int main() { int x=4; ...
1
vote
2answers
37 views

Check even parity from byte

I've found a piece of code on Stackoverflow and edited it to my needs. source: How to check if value has even parity of bits or odd? It works like a charm, but I can't get my head around WHY it works....
0
votes
3answers
32 views

Read digits from a number using sscanf

I am trying to read/extract two digits number using sscanf. facing some issues. char* str ="2019/05/28"; int x,y,z; sscanf(str, "%d/%d/%d", &x, &y, &z); It reurns me o/p as 2019, 05, 28 ...
-1
votes
0answers
36 views

What is the most efficient way to write MPI in C to read from ANY file then use the input for linear algebra? [on hold]

I'm trying to write MPI to make a square matrix (A) that is nXn. It should read from the command line -r n to initialize A with random numbers and -d n to create a diagonal matrix. Also, -f filename ...

http://mssss.yulina-kosm.ru