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
-1
votes
0answers
15 views

Semaphore Creation [closed]

So my semaphore takes the value of -1 even tho I set it to 1, why doesn't it takes the value 1, and how can I fix it? int sem = semget (8790811, 1, 0600 | IPC_CREAT ); exit_on_error (sem, "...
-3
votes
0answers
15 views

C code doesn't run inoutput window but runs correctly if integrated terminal is used

I am currently running a simple c program. The problem is if i run it in vscode using coderunner it does not show any output and keeps running until i force it to stop. But the same program runs ...
0
votes
1answer
14 views

Using scanf to get user inputs for dynamic arrays in c

When I try to get user input for the dynamic array, it stops at the first for loop. It gives me an error that my program has stopped working. Help me out! #include<stdio.h> #include<stdlib.h&...
-1
votes
2answers
32 views

How to print ASCII codes for letters?

How do I create a program where the input of a letter (a-z) is converted to ASCII and printed out. I am stuck at the point where it has to show all the ASCII numbers before it. Let's say if the user ...
0
votes
1answer
18 views

Question about address values increasement(x86, linux) [duplicate]

Let's say that I have a code like below #include <stdio.h> int main(void){ char char_array[5] = {'a', 'b', 'c', 'd', 'e'}; int int_array[5] = {1, 2, 3, 4, 5}; int i; char *char_ptr; int *...
-1
votes
0answers
21 views

How to use fgets whithout printing the buffer?

I'm coding a menu to a short program where you can use ALT+'letter' as shortcuts, but in the body of my program, the usage of fgets prints out the 'letter' of the shortcut, if i tipe abcd then ALT+N ...
1
vote
1answer
20 views

When I run my code, i get a segfault, but when the debugger runs it, it says there is no issue

I'm doing an assignment that is working with shared memory, and i'm getting segfaults whenever I run the code. So i tried using the GDB debugger to see where the fault is occurring,but when it runs ...
2
votes
0answers
41 views

How to weight other factors when using Dijkstra

I'm solving this problem where we have a graph, and are trying to get from node 1 to node N. The edge weights are the "cost" and each edge also has a "flow" value. For any path from node 1 to node N, ...
-1
votes
0answers
26 views

How do i access struct members through a const void*

So in my class I'm taking, we are doing void * to access and manipulate a Queue. I'm having problems wrapping my head around this issue here: typedef void Queue; //.. typedef struct { ...
3
votes
1answer
20 views

How to disconnect a single process from a shared memory object

So I have an assignment to create a library of functions that can create a posix shared memory table, add a record, delete a record and close the table. For the close_table function my prof wants it ...
0
votes
1answer
29 views

Running Ruby in C

Im trying to run a block of Ruby code inside a C program. I have the following code: #include <ruby.h> int main(int argc, char* argv[]) { /* construct the VM */ ruby_init(); /* ...
0
votes
0answers
44 views

Address 0x0 is not stack'd, malloc'd or (recently) free'd in C

i'm developing a program that should read line from a file and retrieve information manipulating them. The file in question is: WORD abc TOTAL 10 FILE /home/user/Scrivania/find/try OCCURRENCES 2 0 0 ...
0
votes
1answer
24 views

merge two sorted linked list into one linked list (recursion)

I had to write a recurssive function that receives two sorted lists: typedef struct listNode { int* dataPtr; struct listNode* next; }ListNode; typedef struct list { ...
1
vote
1answer
28 views

C socket problems - random client address and port number

I have a really simple exercise to do: make a socket where when a client is connected, the server display its information (address and port number). I wrote this: client.c #include <stdio.h> #...
0
votes
0answers
17 views

Semaphore Execution TIme

Can someone tell me the right way to calculate the execution time for the problem? I am a bit new to multi-threading concepts and semaphores. My understanding involves adding the execution time for ...
0
votes
0answers
10 views

ADT MAXHEAP in c

i am trying to implement an ADT of maxheap in c. i am having trouble with the heapify function. this is my struct (which is located in the c file) #include "MaxHeap.h" struct t_Node { element ...
-4
votes
1answer
28 views

How can I check if an element in an array is equal to something in C? [closed]

My function is as follows: bool checkWin(spaceleft) { int i; int counter = 0; for(i=0;i<7;i++) { if(spaceLeft[i]==0) { counter++; } }...
-1
votes
0answers
22 views

Problem with Fibonnaci succesion on my code

I'm doing a program in which I ask for a number and this tells me if it is within the succession of Fibonacci. I have to do it with Arrays, but the program doesn't do what I ask, can anyone help me? ...
-4
votes
4answers
46 views

Pointer arithmetic of unspecified type with known size

void * ptr = NULL; // array of unspecified 13-byte type for (int i = 0; i < 10; i++) { printf("%i ", ((char (*) [13]) ptr) + i); } putchar('\n'); Output: 0 13 26 39 52 65 78 91 104 117 So ...
0
votes
1answer
21 views

Getting unrealistic values with dht22 even though the bits it sends are right when looked at with an oscilloscope

I am using a STM32F407 microcontroller with the program CodeBlocks and i am trying to use the DHT22 temperature and humidity sensor. There are probably other posts like this but I looked at all of ...
1
vote
1answer
68 views

can GOTO create an overflow in stack memory? StackOverflow?

I'm not an expert in C but I do well, my main is embedded systems and microcontroller programming. I know there's a myth of avoiding the use of the GOTO instruction because it creates spaghetti codes....
1
vote
2answers
32 views

how do I add up the sum of the digits of a number except for digits that repeat themselves in c?

I have an assignment and I need to add up the digits of it and ignore the once that repeat themselves for example 234111 -> 2 + 3 + 4 + 1 -> 10 I tried doing this: #include int main(void) { int ...
0
votes
0answers
24 views

epoll sets EPOLLHUP on usable fds containing data

I have been working with different languages (Java, PHP, ASP, JS ...) for years, but never got around to C. Always thought about it, but there was always tomorrow. Now I finally did do it and have ...
1
vote
1answer
41 views

Saving numbers (sequence of digits) from a string in an array of pointers to a char

I am supposed to save every sequence of digits from a string in an array of chars , this is what i tried: #include<stdio.h> #include<ctype.h> #include<string.h> int check_number(...
0
votes
1answer
29 views

valgrind report memory loss using getline function

I am writing a grep program in C. I am using getline() inside a while loop to get all lines from stream (file or stdin). The lines are stored into char *lineText buffer inside a struct i defined, ...
1
vote
0answers
57 views

Does using `restrict` when initializing a new pointer actually do anything?

I have been reading about the restrict keyword and every example I've seen uses it when defining a function. void foo (int *restrict bar, float *restrict baz); I have been reading through articles ...
1
vote
2answers
59 views

Problem in sorting alphabetically a linked list in C

i'm trying to sort alphabetically a linked list in C. The linked list i used is the following: struct lineList{ //structure with all the line of the input file char *line; struct lineList *...
0
votes
0answers
8 views

ESP32 and Firestore/Google Cloud Functions

I am trying to get data from Firestore onto my ESP32. I want to do this either directly, or by calling a google cloud function (likely python) which will interface with firestore and return data back ...
0
votes
2answers
71 views

Cannot declare a void function before the main() in C

I'm a beginner in C language and in my previous question I have asked about proper function declaration order in C. I was told that in standard C, it is necessary to declare functions before calling ...
1
vote
1answer
30 views

Basic input from shell in C [duplicate]

Lets suppose I'm using netcat tool to transfer a file: cat myfile.txt | nc -klvp 3000 How can a C program read this input? (i mean, the string which is returned by "cat" command). How is this ...
1
vote
1answer
21 views

How to Correctly use Variadic Macros to Call Other Macros [duplicate]

I know this isn't a fix my build error site, but I've exhausted all my options. None of my coworkers can see anything wrong. I have a set of macros in the format EventWriteQuic* and take variable ...
-6
votes
0answers
31 views

ft_printf.c function test hhhlll failed [closed]

ft_printf.c job. Throws an error in the test: = test_hhhlll ==================================================================` ` [33mObject deleted [0m` ` [32mlibftprintf.a OK ! [0m` ` [...
-2
votes
0answers
50 views

Generate every possible Integer that has the same number of ones and zeroes [closed]

I want to generate every integer that has the same number of ones and zeros in the binary representation. It seems that generating every int and then counting the bits takes my computer ages. Is there ...
0
votes
1answer
32 views

i need help there's wrong in my codes and to improved my codes?

input 0,0,0,0 output no entry insert , input 1,1,1,1 ouput all entry insert, input 1,1,1,0 ouput three inserted entry, input 1,0,1,0 ouput gate 1 and gate 3/ input 1,1,0,0 output gate 1,gate 2, input ...
0
votes
0answers
9 views

Setting PD12 pin high on BlueGecko BGM11s, not able to write data to app over BLE

Currently I am using a modified version of the led app for the Blue Gecko BGM11s, but instead of the LEDs on the BRD 4001A Rev. A which are PF4/PF5 , I have flashed the module with a combined .s37 ...
0
votes
1answer
29 views

How do I read from a file in C if the file has accented chararcters such as 'á'?

Another day, another problem with strings in C. Let's say I have a text file named fileR.txt and I want to print its contents. The file goes like this: Letter á Letter b Letter c Letter ê I would ...
0
votes
0answers
35 views

Segmentation fault, cannot access memory [closed]

I was following craftinginterpreters and encountered with an error right at the beginning of part 3. When I run the following function, it gives a Segmentation fault. #define GROW_CAPACITY(capacity) ...
-2
votes
1answer
21 views

Calendar program has a declaration syntax error [closed]

I'm making a calendar. When I compile it I get a "Declaration syntax error". int get_1st_weekday(int year) { int d; d= (((year - 1) * 365) + ((year - 1) / 4) - ((year - 1) / 100) + ((year) / 400) ...
0
votes
1answer
45 views

how does a c-compiler interpret whitespace in source code? [closed]

Does a c-compiler interpret whitespace in source code somehow else than in a string? I know that a c-compiler interprets whitespace in a string as a ASCI-value.
-4
votes
1answer
25 views

how to write a char variable in a file? [closed]

void main { char width; width = 2; FILE *file = fopen("file.txt", "w") if (file != NULL) { fputc ('c', file) //writes correctly. fputc (width, file) //has no effect fclose(file); }} in the ...
-2
votes
3answers
56 views

sprintf_s and access violation

I've been getting "0xC0000005: Access violation reading location errors" in Visual Studio on Windows with a C/C++ program and have attempted to simplify to illustrate my question. The code below runs ...
0
votes
0answers
20 views

Remote Control a PC and run a .exe [closed]

I am currently making an internship at a certain company and now I was given a task with something I've never done before: I should remote control/access a PC (a CMW 500) which is running on windows (...
2
votes
1answer
49 views

C: How to iterate over all possible values of `signed int`, from `INT_MIN` to `INT_MAX`?

I want to iterate over all possible values of signed int, from INT_MIN to INT_MAX. The obvious code for (int x = INT_MIN; x <= INT_MAX; x++) do_something(x); is broken due to undefined ...
0
votes
1answer
29 views

Direct Memory Mapping GCC Cross-compilation

I am using the gcc cross compiler on a windows machine for an ARM CortexA9 for a bare metal application. For direct memory mapping I need to access the address 0x8000_0000. I use the following C-Code: ...
0
votes
0answers
11 views

How do I make button label translations work in GTK?

I'm trying to make a simple dialog window in GTK 3 where the button labels are set in accordance with the chosen language. Here is my program gtklocale.c: #include <glib/gi18n.h> #include <...
0
votes
1answer
31 views

In what is macro preprocessor implemented on its own?

I am currently reading: enter link description here -Which is gcc the C preprocessor documentation. But still even if I look for other documentations, I am not able to find the true macro ...
2
votes
1answer
46 views

C / Copy String with dynamic malloc, from const char * org to char ** cpy

I want to copy a const string const char * org to char **cpy, but my code doesn't work. I was thinking getting the lenght of my original string and and using malloc to dynamically allocate memory, in ...
1
vote
2answers
38 views

Storing strings in stack vs code section in C?

I'm currently in a C class, and am very confused as to where string literals are stored. I understand that a string is just an array of chars, so something like char c[5] = {'A','B','C','D', 0}; is ...
0
votes
1answer
24 views

system calls write data to a file based on if condition

program to read data from afile which contains integer values and check if they are even or odd and write data to two seperate files named as even.txt and odd.txt don't get me wrong i am just a ...
1
vote
2answers
26 views

*** stack smashing detected *** with double array in double for cycle

As the title says im hitting stack smashing detected with my code. The weird thing i cannot understand is that it outputs all the positions of the moons correctly and then it stack smashes. When i set ...