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
1answer
21 views

I don't understand why I'm definitely losing blocks of memory

As a project I'm creating a student database. However according to valgrind there's memory leak in my program and I don't know why. I can't really say much more: I don't understand why memory is being ...
-2
votes
1answer
39 views

need of maximum value in int

I just started programming in c and i know some basics of python so when i set a very big int value to a variable in python say '58944651132156484651' and print the variable everything will be fine ...
2
votes
1answer
18 views

ATMEGA328p convert analog value to voltage

This is an extract of the official ATMEGA328p data sheet page 261: As the documentation say Vin * 1024 ADC = ---------- Vref What I don't understand is an analog pin can provide us ...
-1
votes
0answers
13 views

Parent-child relationship

I'm working on an application to use the explosion and implosion of the bills with parent-child relationships. I have my database with the parent field and the child field (and other). By clicking on ...
0
votes
0answers
13 views

intializing MPU6050 using NRF52840 development board

As a base start I downloaded the NRF5 SDK V15.3.0 and modified twi_sensor_pca10056 program using editor software Kielu5 to initialize the MPU6050. My current problem is that I am not getting correct ...
-3
votes
0answers
21 views

changing data of an two dimensional inside a function [on hold]

I am trying to change the data of the array inside a function but i am not managing to it this way. What is wrong in my code? http://tinypic.com/r/mi0xn5/9 I don t know how to put the code here , it ...
0
votes
0answers
19 views

Is this correct?What will be the output? [duplicate]

According to me the output should be 511 but its coming 500 why? #include<stdio.h> void main() { int a=3,b=5,c=3; printf("%d%d%d",a=5,a==b,a>c); }
1
vote
0answers
15 views

how to use audit in linux to monitor a file using libaudit

A previous question showed code for libaudit How to use libaudit? but the answer is not a complete example. I added include files to create a mwe, and it doesn't work. In this case, I am monitoring a ...
-3
votes
2answers
28 views

Pint all the odd numbers between 2 numbers using pointer and array

I don't know what's wrong with the code but segmentation fault is coming up. If l=2 and k= 5 then output should be 3 5 #include<stdio.h> int* odd(int,int,int*); int main() { int l,k,*...
0
votes
0answers
16 views

Why is this expression evaluated from right to left? [duplicate]

I was given this interview question. Why is this expression evaluated from right to left? #include <stdio.h> int main(void) { int i = 0; printf("%d %d\n", i, i++); // output is 1 0 ...
0
votes
0answers
16 views

Convert file from PDF format to PWG-Raster format (for IPP printing) in Windows

I'm trying to use the new standard for printing which is using the PWG-Rater file format with IPP (Internet Printing Protocol) The specification for this file goes here: https://ftp.pwg.org/pub/pwg/...
0
votes
1answer
30 views

count the total no. of keywords in the file

I want to count the total no. of keywords in the file but the code counts those keywords that are used to declare the variable. void main() { //2d array used to store the keywords but few of them ...
2
votes
2answers
43 views

Signed Char Decimal to Hexadecimal Conversion in C programming [duplicate]

I was trying to work on something and I basically have two questions. When creating a signed char, how do you a) what is the convention of initialization and print statement used to print it in ...
1
vote
1answer
47 views

Is there a way to find the position of a special character '\n' in a file in C?

I want to find the position of a '\n' in a file and print out the remaining characters after \n I've tried to use lseek to find the number of times '\n' occurred but I cannot seem to find the ...
0
votes
1answer
29 views

How to use gcc on macOS to produce assembly with C source included?

I'm on macOS (latest version). I know that gcc can produce assembly source code with the -S option. That works fine. My problem is that I can't get it to produce assembly source that is annotated ...
3
votes
0answers
72 views

Use function or function pointer when dependency is inverse? [on hold]

I'm developing a MCU (MicroController Unit) development system. It is composed of 2 kinds of MCUs which play different roles in the system, and their programs are different. They use the same ...
0
votes
0answers
15 views

How can i use MCLR on a pic18f4550 using Proteus?

I'm trying to use Master clear(MCLR) on a pic18f4550 with Proteus, but whenever I press the button to do so, the red and blue dots that represent on and off in Proteus turn yellow and the LED doesn't ...
1
vote
1answer
47 views

Array is printing with weird question mark symbols when printing fibonacci sequences

When printing each Fibonacci sequence the first couple of sequences print in weird symbols or not at all if printing more than 8 sequences. #include <stdio.h> #include <string.h> #include ...
-1
votes
1answer
56 views

Self provoked buffer overflow in C

I was wondering if it's possible to generate a buffer overflow programmatically, I mean, without any user input. I've been trying to cause a buffer overflow with the memcpy function, copying the ...
0
votes
1answer
56 views

Why is getchar() required to not terminate my infinte loop? [duplicate]

In this program , getchar is apparently needed to continue the while(1) loop. If I remove getchar(), the program terminates after printing the sum of the two numbers. while (1) { printf("Input ...
1
vote
1answer
68 views

Why my code refuse to compare the generated hashes

I am working on crack assignment from cs50. I am planing to start with comparison hashes from 1 character password but it doesn't work at all. #include <stdio.h> #include <cs50.h> #...
0
votes
1answer
28 views

Makefile No such file or directory

I'm trying to do some simple linked list practices to familiarize myself with C. I currently have the following makefile. CC=gcc CFLAGS=-Wall app: linked_list.o app.c $(CC) $(CFLAGS) linked_list....
0
votes
2answers
41 views

Why is pthread_equal threadsafe?

If I look at the implementation of pthread_equal it looks as follows: int __pthread_equal (pthread_t thread1, pthread_t thread2) { return thread1 == thread2; } weak_alias (__pthread_equal, ...
-1
votes
0answers
36 views

The read file outputting weird values when using fopen in C Programming [on hold]

I have a file with a bunch of decimal values (4221 lines of them), like: 0.0331102850854 0.0478929910233 0.022441378566 0.0156259099328 0.0166854656527 0.0124127406264 0.0476716008822 .... ...
0
votes
1answer
53 views

fprintf prints to file a garbage value in the middle of the correct output

the output to the file is different than to the console. in the console, I got the wanted value: *************** Line: 100 *!***** *************** *************** Line: 101 *!%%%** *************...
0
votes
2answers
52 views

How can I read a file content multiple times in C

I am trying to do a simple todo list in C, but the read option only shows the correct info on the first run. If I add a new item, then I need to close and open the program again to show the updated ...
0
votes
5answers
105 views

Is there a way I can shorten this if statment?

I have this really large if statement and it does not look pleasing to the eye as well as not being as efficient as possible. I'm making a program that (depending on the users input) runs a ...
-2
votes
4answers
53 views

fscanf() != EOF as exit condition of loop exits at the wrong time

I'm taking the input from this file, which I know contains a series of elements of type: typedef struct{ char artist[50]; char title[50]; int num; //numero traccia int minutes; ...
-1
votes
3answers
41 views

I made a stack using linked list (without array), but my pop function is not working

In my pop function, I am storing the address of head in temp and then going forward. When I get a dead-end in temp, I remove it by assigning NULL to it. When I am printing the stack however, it is not ...
-2
votes
2answers
36 views

Big latency in bluetooth communication

I have tried to write wireless servo control using two arduino nano v3 boards and two bluetooth 4.0 modules. First code is transmitter. It's very simple. It reads PPM signals and transform to ...
-2
votes
0answers
41 views

Why does my program terminate without executing the switch statement? [on hold]

This is a simple C program for converting temperatures. After I enter ch the program terminates ignoring the switch statement? Why does this happen? The output I get: For Celsius to Fahrenheit ...
-4
votes
3answers
58 views

How can I start with this problem and fix my code?

The question: write a program that gets a list of numbers ( lets say 4 numbers ) and an extra number and checks if the extra number equals to the multiplying of two numbers from the list. If yes ...
-3
votes
1answer
59 views

Why are the C operator precedence rules in the order that they are in? [on hold]

I'm following this book, and the author stated that the language used in the book has the same operator precedence rules as C. However, he doesn't mention why the precedence rules are in the order ...
0
votes
1answer
66 views

problems with messages queue

this program should create a fixed number of childs (30), and these threads should communicate each other for purposes that maybe I can explain after. occurs the error 22: invalid arguments both on ...
1
vote
0answers
30 views

MmCopyVirtualMemory failing, code is correct

My situation is that MmCopyVirtualMemory almost always (%99 of the time) returns STATUS_PARTIAL_COPY. (Im operating in a Ring0 Driver) I've tried so many different things, like using different ...
0
votes
3answers
73 views

C - Store float to char array and reverse

Let's say I have this float: float f; And I want to store it in a char array: char bytes[4]; And then reverse the array back to float. Any help? Thanks in advance. EDIT: Here is the code AND IT ...
0
votes
0answers
40 views

How to identify which file implicitly relies on linkage with a library?

I am working on en embedded project. I have integrated open source sub-projects in it (i.e. code I did not write). Compilation is fine but I have linkage errors: gcc-arm-none-eabi-7-2018-q2-update/...
0
votes
0answers
20 views

Import RData file into C

I want to know how to import a RData file into C, the data file contains a series of integer. I have already the method to import txt data file into C, but I do not know how to convert RData file ...
1
vote
5answers
139 views

What does *(int32_t *)(a + 4) = b mean?

I have decompiled an .so file (from an ARM lib in an Android app) using retdec and among the code I could find instructions like this: int32_t a = `some value`; int32_t b = `another value`; *(int32_t ...
5
votes
3answers
94 views

Does a stray \ [backslash] have any meaning in C code? [duplicate]

For the code: #include <stdio.h> int main(void) { \ printf("Test"); } compiling via gcc -Wall -Wextra -Wfatal-errors test.c gives no warnings. However for other stray characters, compiling ...
0
votes
0answers
21 views

Socket get last ACK interval for ongoing data?

Sometimes when reuse a socket, check the socket healthy may be better. Socket may be lost in sometimes, it try to retransmit data before timeout, but nothing ACKed. Can I just get the last ACK ...
1
vote
2answers
102 views

strtok returns NULL despite not having reached the end of the string

I am writing a program that parses input from stdin and calls functions according to the input. The inputs my program is supposed to handle are the following: end //stops the program report //prints ...
-3
votes
1answer
69 views

Why do we write “struct node” in C instead of writing only “struct”? [on hold]

Why do we write struct node in C instead of writing only struct? Is there any use of it? Can anyone explain it? struct node { struct node* next int a; }; Can we write ...
-4
votes
0answers
35 views

reading files from a directory non-recursively in c language [on hold]

Blockquote I'm new to c language. I have no idea why the below code is reading files recursively from a directory instead of sequentially. I want the below piece of code to read the files in the ...
-3
votes
2answers
45 views

How to convert from Hex to Decimal using only Integers in C [on hold]

I'm receiving the following data over a serial port: <0x1b><0x2e><0x15>... Each value enclosed in '<>' is a single byte. I require the third byte from the data so i do this: ...
0
votes
0answers
64 views

(C language) I would like to know why this code is used to specify address

#define NVRAM1_PAGE1_FIRST_ADDRESS 0x1000 extern volatile INT16U NVRAM_content[128] __attribute((nodp, addr(NVRAM1_PAGE1_FIRST_ADDRESS))); This array surely start address from ...
0
votes
0answers
28 views

NDK - Failed to Link C shared library libopusenc

My project consists of 4 static libraries (.a) and I am trying to link them using cmakelist. But let's focus on the 2 problematic libraries. The libraries used in the project: libogg, libopus, ...
0
votes
0answers
26 views

how do I attach child structs data to a parent struct?

I have an issue with nested structs for a pretty complex assignment (in my opinion): I don't know how to ensure the child struct data is added to the parent struct I've been getting a blank in ...
0
votes
1answer
42 views

How to parse from char array using yacc?

I am trying to parse string from buffer. Lex code %{ #include <stdio.h> #include "y.tab.h" %} %% "Type:[0-9]+" { printf("lex-TYPE\n"); return TYPE; }; %% Yacc ...
1
vote
0answers
17 views

CMake add_subdirectory use different compiler [duplicate]

I have a CMake project that consists of several sub-projects added to the main project using add_subdirectory function. I use a custom compiler for which I created a helper file which sets the ...