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
9 views

Deleting first node in link address and getting illegal address on function return

Delete node function deletes a given node from a link list. The function correctly deletes any node except the head node. The link list (head) has 6 nodes 0,1,2,3,4,5. the delete function correctly ...
0
votes
0answers
9 views

Count number of adjacent pairs in Binary

Let's say that I'm given an integer n, which is read from the user. I would like to count the number of adjacent pairs of 1's that is has. So for example, let's say I'm given the number 31. The ...
2
votes
1answer
31 views

How to alloc memory manually

when i was studying pointer, I had an idea to get a better view about the memory allocation, so i tryed to alloc mannualy memory to the pointer, but it dont works. can someone explain more about it? ...
0
votes
1answer
18 views

Why pthread_join on itself doesn't result in error or deadlock?

https://repl.it/repls/ColdSilentTriangles #include <stdio.h> #include <pthread.h> pthread_t th; void *fp(void *args) { printf("Thread running..."); pthread_join(th, NULL); printf("...
0
votes
1answer
24 views

What is the value of i which I am assigning to \0?

I am not sure what the value I am assigning to \0 is here. Here it is my code: #include <stdio.h> #include <string.h> int main() { char Str[100], RevStr[100]; int i, j, len; ...
0
votes
0answers
8 views

Error/Conflict with “replace” with winsock2.h, fix?

I am making a simple project simulating UDP protocol. I am trying to set up a connection using winsock2.h, as I am using windows and also using Clion and cygwin. As soon as I add the winsock2.h ...
-2
votes
1answer
21 views

fgets can't display on 1 line with multiple “%”

I want to display fgets() input on 1 line, here the code: printf("%s study at %s and he is %i years old", siswa01.name, siswa01.school, siswa01.age); When I run the program, the output was like this:...
0
votes
0answers
26 views

How to extract specific bits from an offset

Im attempting to create an assembler in c of a sorts in which i take an input from a file that contains a command, in this case branchifequal i then take its opcode which is 10 so byte[0] = 0xA0 and ...
0
votes
1answer
28 views

A struct that contains two double pointers, seg faults when accessing second double pointer

I am trying to access the second double pointer but it immediately seg faults only after accessing the first one. What is going on? It seems to work without the second double pointer but I have no ...
0
votes
0answers
11 views

Access Struct members after pass to pthread function call

I am trying to access members of my struct that is passed to a function that was called by a pthread process. It is simple, but for some reason I cannot figure it out. I have tried using data.count ...
-3
votes
0answers
15 views

How to mutate array struct in C

Here is a problem from a "CodingSignal" practice test. Time ran out and I wasn't able to solve the problem. Anyone know how you would code this in C? Prompt: Given an integer n and an array a of ...
0
votes
0answers
10 views

Hexadoku Solver? Stack Buffer Underflow Error?

So for an assignment, I had create a program that that implements a simple Hexadoku solver (in the second part you can implement a complex Hexadoku solver for extra credit). Hexadoku is an extension ...
0
votes
0answers
22 views

Converting an assembly jump command to its hex value in C

Im attempting to create an assembler in c which just reads the instructions from an input file and then translates them to their machine/hex code. So far so good until i hit the jump instruction, ...
0
votes
1answer
8 views

How to add transform functions from CMSIS DSP library to a Makefile?

I wrote a code that used arm_cfft_f32 function from CMSIS DSP library. How to add CMSIS DSP library to Makefile of my project? The Makefile generated by STM32CubeMX for STM32F407 chips. I copied .c ...
-1
votes
0answers
34 views

How to fix code for separating integer from fractional part

I wrote a function that receives a float number, changes it to its fractional part and returns its integer part. The fuction is structured as a if-else statement (to differentiate positive from ...
0
votes
0answers
12 views

drawing a pixel using DMA

I'm trying to draw a single pixel using DMA2D. I did the following code it's not working at all. LCD Display Width is 320, Height is 240. I assumed a 1x1 pixel rect as a pixel. DMA2D_HandleTypeDef ...
0
votes
2answers
31 views

My user input isnt multplying my stored values

Im making a program that asked the user how many pennies nickels dimes and quarters they have then tells them how much money they have after. I wrote the program but I cant figure out how to make the ...
-2
votes
0answers
41 views

C file input issues

I have been running into an issue with my following code. I am trying to prompt the user for an input file. This is the entirety of my code int main(void) { //variables char filename[50]; /...
-1
votes
0answers
20 views

Print contents of linked list to a txt file

I made a linked list of words from a txt file in UTF-8 and I'm trying to print out that list of separated words to another txt file. I tested my implementation of the linked list and it works(I am ...
0
votes
0answers
9 views

Parent-child IPC via Named pipe: Segmentation fault

I am creating own shell. Requirement: The main (parent) process forks into a child process and executes the command in child. The child then shares the output to parent via named-pipe I am using ...
0
votes
0answers
35 views

How to detect in C++ if exe is running inside cygwin or cmd

I'm writing C++ application using Visual Studio. I want to detect in runtime if application is running in cygwin or cmd. I need it because I want to print coloured text, and it's done differently in ...
0
votes
0answers
29 views

How to convert a number in a text file to its hex value in c

Im attempting to create a basic assembler in C in which i am just simply taking in instructions from an input file and then translating those instructions into machine language/hex values. I am stuck ...
0
votes
0answers
16 views

Linux C open() - creating new file based on existing ,with the same permissions

I have to create a program that will create new one or overwrite existing(outfile), with the content of an already existing one(infile). For me, this is easy, I've already done this. But my problem is,...
0
votes
0answers
16 views

How to make sure doxygen-style documentation comments aren't missing from C/C++ code?

I want to run some kind of linter or static code analysis on C/C++ code which gives a warning if there is code with missing documentation, for example a function without its doxygen-style ...
1
vote
1answer
14 views

Counting Sort displays a weird behaior

I have implemented a Counting Sort in an assignement given to us by a teacher but sometimes it doesn't work for large arrays, here is the code for the algorithm void countingSort(int *t,int n){ ...
0
votes
1answer
20 views

Running Exec() Command Parameter

I am student developer and beginner in C programming language. I have a task and I did not find a clear solution according to my level. I want to run exec() function in child process. I created parent ...
0
votes
0answers
33 views

How to write a basic assembler in C?

So im attempting to write a basic Assembler in C that will take in two files, one input and one output. The Input will contain the instruction and the output will contain the assembled code which can ...
1
vote
0answers
8 views

CAN bus nulling data at transmission

I'm trying to transmit some data by CAN bus between two STM32 blue pill MCUs (STM32F103C8T6). The data array to be transmitted is composed by data read from other CAN bus devices, from ADC pins and ...
-3
votes
1answer
52 views

Converting python program to c [on hold]

Socket connection is established for communication between Raspberry pi and GPU in adhoc network. Client side code def write(self, buf): if buf.startswith(b'\xff\xd8'): # Start ...
0
votes
1answer
31 views

Functions in math.h don't return the expected value

The program I'm making is supposed to calculate the following function: f(x,y)= 2 sin(x) + cos(y) - tg(x+y) I tried to do the following: #include<stdio.h> #include<math.h> double ...
-3
votes
0answers
22 views

How do I make a nested loop to find nth prime number?

So, I made a previous post and I have been editing it for awhile and it is still not working. I was told I need to make a nested loop to find a nth prime number. So, the assignment says to that I need ...
0
votes
1answer
21 views

How to print every element in a linked list except for the last one

I have a linked list where I want to print every element except the last one. while (node != NULL) { printf(" (%d,%d) ", node->x, node->y); node = node->next; } This is ...
1
vote
1answer
19 views

Do I even need `-pedantic` if I specify the standard to ANSI C with `-std=c89`?

If I specify the standard to ANSI C with -std=c89, my code won't run until I perform certain changes to make it compliant with the standard. So do I even need -pedantic at this point if I've already ...
-3
votes
2answers
33 views

What will be the correct output for this question?

here i and j both should be modified with the value 2.But given answer on geeks for geeks is i=0 and j=2 #include stdio.h void f(int *p, int *q) { p = q; *p = 2; } int i = 0, j = 1; int ...
0
votes
2answers
17 views

Parent/Child and pipes in C, child-parent comunication

I have a parent program that sends a integer to a child, and the child program multiplies the number by two and gives back to the parent. In a main program I create a pipe and fork() and execl() the ...
0
votes
1answer
19 views

What are the ways to check a process with specific pid exists and active?

What are the ways to check a process with specific pid exists and active? I am using Ubuntu Linux with gcc.
0
votes
0answers
31 views

the number with a and sum of its positive divisors b then a+b is a perfect square? [on hold]

I've been dealing with my homework for a week but I haven't made any progress. The question is that write a program that reads an integer from the user (keyboard), namely “n”. Your program should ...
0
votes
2answers
29 views

Segmentation Fault in C when Initializing an Array

I am trying to dynamically create an array in a separate function and store some variables inside of that array and I came across the following: how come when I write; #include <stdio.h> #...
-1
votes
0answers
13 views

Mutex VS Condition variables VS Synchronization Primitives

I am starting to learn about Linux Operating System, and I am confused with differences between mutex, conditional variables, and synchronization primitives. Which one is the best to avoid deadlocks ...
0
votes
0answers
18 views

Server to client message sometimes fails

The client sends the message "--" to the server, the server responds with the message "Test". However on the 4th time, the message from the server did not come through, and I had to terminate the ...
0
votes
1answer
22 views

How to open web urls using C language?

I know the function system("START www.weburl.com"). However, I need to change link during program running and open different parts of that website. I have to add to that link, for example, www.weburl....
0
votes
0answers
35 views

How to open file using POSIX interface (open(),write())

I'm trying to open a file with the POSIX interface with the plan of then writing to it. However, I can't even get the file to open properly. I have checked similar questions but they don't seem to fix ...
0
votes
1answer
41 views

How can I display my Binary tree horizontally?

I was working on Binary Search trees and my concept on recursion is not the best that it can be. So I chose to use recursion to do all the basic tasks. The only problem that was having was with my ...
0
votes
0answers
35 views

What means valgrind m_mallocfree.c failed?

in the beginning it was just a segmentation fault in line 141, i was trying to find why my code broke and then valgrind failed for (i = 0; i < Points; i++) { min = 999999999999;enter code here ...
0
votes
0answers
11 views

2 bounder buffers shared with pthread calls, mutex locks and busy waiting

I am generally new to C so I have loads of syntax errors and referencing problems. I have written prodcons.c, a Struct that will create a bounded buffer of size 50 and a few helper variables. In main ...
1
vote
1answer
34 views

Rust Destructors and ownership

I almost asked the same question the other day but in context of c++. I try to replicate destructors and constructors in my c programming. That means for every object or struct there is an ...
0
votes
0answers
33 views

How to dynamically execute C or C++ code in iOS?

I have an NSString containing C or C++ code in iOS, for example: #include <iostream> using namespace std; int main(){ cout << "Hello World" << endl; return 0; } How can ...
-1
votes
1answer
22 views

How to fix error: incompatible types when returning type 'struct {aka struct <anonymous>}

I'm making a code that returns a struct with random values. I keep getting error: incompatible types when returning type 'student {aka struct }' but 'struct student *' was expected return s; I've ...
0
votes
2answers
50 views

Snake game in linux source code (C language)

I've been studying a source code in C about a snake game for Linux console (code found on github). Can someone please explain me the move function? Also, is there a way to modify this code in order to ...
0
votes
2answers
55 views

Is there any random generator library except rand(), which developer can manually set the seed?

I want to verify that if the seed is same, the resulting pseudo random number is same. Using rand() is the simplest but I'm looking for safer way. I found that using device entropy with /dev/random of ...